docker離線安裝(二進制方式)

一、安裝

1.1、下載包

在https://download.docker.com/linux/static/stable/x86_64界面下載一個docker tar包

例如docker-19.03.4.tgz

1.2、解壓包

 tar -xzvf docker-19.03.4.tgz

1.3、把解壓出來的複製到/user/bin目錄下

sudo cp docker/* /usr/bin/

1.4、使用守護進程方式啓動

sudo dockerd &

1.5、現在你可以嘗試着打印下版本號,試着看看 images,看看 info,看看容器了

sudo docker -v
sudo docker images
sudo docker ps -a
sudo docker --version
sudo docker info

二、把docker註冊爲service服務

2.1、執行創建docker.service命令

sudo vi /usr/lib/systemd/system/docker.service

2.2、輸入以下內容

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.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
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
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target

2.3、測試是否成功

sudo systemctl enable docker.service 設置爲開機啓動
sudo systemctl start docker.service 啓動
sudo systemctl stop docker.service 停止
sudo systemctl restart docker.service 重啓
或者
sudo service docker restart 重啓
sudo service docker stop 停止
sudo service docker start 啓動

三、解決sudo docker問題

3.1、創建docker組

sudo groupadd docker

3.2、將當前用戶加入docker組

sudo gpasswd -a ${USER} docker

 3.3、重啓服務

sudo service docker restart

3.4、刷新docker成員

newgrp - docker

3.5、大功告成

可以直接使用docker images二不需要增加sudo了

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章