在线安装docker
可以参考菜鸟教程:https://www.runoob.com/docker/centos-docker-install.html
- 安装插件
yum install -y yum-utils
- 添加仓库地址:
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- 安装指定版本的docker-ce和docker-ce-cli:
yum install docker-ce-20.10.24 docker-ce-cli-20.10.24 containerd.io
- 启动docker,设为开机自启动:
systemctl start docker
systemctl enable docker
离线文件安装:根据实际情况下载离线包
docker-Linux下载地址
搭建docker环境准备
在能连网的服务器上下载所需的镜像,例如
docker pull mysql:8 (拉取mysql:8镜像)
docker images (查看镜像)
docker save -o mysql-8.tar mysql:8 (将mysql:8镜像压缩成mysql-8.tar压缩包文件)
上传docker压缩包及镜像上传到需要部署的服务器上,然后进行解压,例如:
- 解压docker软件压缩包
tar -zxvf docker-20.10.9.tgz
- 把docker文件里面的内容复制到bin目录下
cp docker/* /usr/bin
- 在/etc/systemd/system或者/usr/lib/systemd/system目录下创建文件 docker.socket和docker.service以及containerd.service
三个文件的内容放最后面,记得先把文件内容加上才能启动docker哦
touch docker.socke
touch docker.service
touch containerd.service
- 重新加载配置文件
systemctl daemon-reload
- 创建组
groupadd docker
- 启动docker
systemctl start docker
- 查看dock是否启动成功:运行命令没报错就没问题了
docker ps
- 设置开机自启动
systemctl enable docker.service
- 导入镜像
docker load -i mysql.tar
- 查看镜像
docker images
- 根据实际情况构建容器,例如:
docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:8
docker配置文件内容:
docker.socket
[Unit]
Description=Docker Socket for the API
PartOf=docker.service
[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target
docker.service文章来源:https://www.toymoban.com/news/detail-436299.html
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
#ExecStart=/usr/bin/dockerd
#ExecStart=/usr/bin/docker daemon --tlsverify --tlscacert=/root/openssl/ca.pem --tlscert=/root/openssl/server-cert.pem --tlskey=/root/openssl/server-key.pem --registry-mirror=http://3cda3ca9.m.daocloud.io -H tcp://0.0.0.0:2376
#ExecStart=/usr/bin/docker daemon --registry-mirror=http://3cda3ca9.m.daocloud.io -H fd:// -H tcp://0.0.0.0:2375
#ExecStart=/usr/bin/dockerd --registry-mirror=http://3cda3ca9.m.daocloud.io
ExecStart=/usr/bin/dockerd --registry-mirror=http://3cda3ca9.m.daocloud.io -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
[Install]
WantedBy=multi-user.target
containerd.service文章来源地址https://www.toymoban.com/news/detail-436299.html
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
到了这里,关于Linux离线环境安装部署docker(超详细)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!