在線安裝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,設(shè)為開機自啟動:
systemctl start docker
systemctl enable docker
離線文件安裝:根據(jù)實際情況下載離線包
docker-Linux下載地址
搭建docker環(huán)境準備
在能連網(wǎng)的服務(wù)器上下載所需的鏡像,例如
docker pull mysql:8 (拉取mysql:8鏡像)
docker images (查看鏡像)
docker save -o mysql-8.tar mysql:8 (將mysql:8鏡像壓縮成mysql-8.tar壓縮包文件)
上傳docker壓縮包及鏡像上傳到需要部署的服務(wù)器上,然后進行解壓,例如:
- 解壓docker軟件壓縮包
tar -zxvf docker-20.10.9.tgz
- 把docker文件里面的內(nèi)容復制到bin目錄下
cp docker/* /usr/bin
- 在/etc/systemd/system或者/usr/lib/systemd/system目錄下創(chuàng)建文件 docker.socket和docker.service以及containerd.service
三個文件的內(nèi)容放最后面,記得先把文件內(nèi)容加上才能啟動docker哦
touch docker.socke
touch docker.service
touch containerd.service
- 重新加載配置文件
systemctl daemon-reload
- 創(chuàng)建組
groupadd docker
- 啟動docker
systemctl start docker
- 查看dock是否啟動成功:運行命令沒報錯就沒問題了
docker ps
- 設(shè)置開機自啟動
systemctl enable docker.service
- 導入鏡像
docker load -i mysql.tar
- 查看鏡像
docker images
- 根據(jù)實際情況構(gòu)建容器,例如:
docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:8
docker配置文件內(nèi)容:
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文章來源:http://www.zghlxwxcb.cn/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文章來源地址http://www.zghlxwxcb.cn/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
到了這里,關(guān)于Linux離線環(huán)境安裝部署docker(超詳細)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!