Centos下docker離線安裝

Centos下docker離線安裝

1、下載docker安裝文件

離線安裝docker,需要下載docker的安裝文件。

地址:https://download.docker.com/linux/static/stable/x86_64/

我下的是最新的版本[docker-20.10.7.tgz],文件不大,只有69M左右。

2、離線docker安裝

將安裝包文件上傳到服務器目錄并解壓。

[root@iZbp13sno1lc2yxlhjc4b3Z ~]#tar -xvf docker-19.03.6.tar

將解壓出來的docker文件內容移動到 /usr/bin/ 目錄下

[root@iZbp13sno1lc2yxlhjc4b3Z ~]#cp docker/* /usr/bin/

將docker注冊為service,在/etc/systemd/system目錄下創建docker.service文件,并配置如下內容保存。

[root@~]#vim /etc/systemd/system/docker.service

[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

3、修改docker工作目錄

/etc/docker/daemon.json文件值,文件不存在需手動創建

# vi /etc/docker/daemon.json

新增以下信息:

{

"data-root": "/app/docker/data"

}

4、設置開機啟動

添加文件權限并啟動docker,執行如下命令:

chmod +x /etc/systemd/system/docker.service? ? ? ? ? ? ? ? ? ? ? #添加文件權限

systemctl daemon-reload? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #重載unit配置文件

systemctl start docker? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #啟動Docker

systemctl enable docker.service? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #設置開機自啟

驗證docker安裝是否成功:

systemctl status docker? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #查看Docker狀態

docker -v? ? ?

docker info

?Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.24/images/json: dial unix /var/run/docker.sock: connect: permission denied

解決方法

docker進程使用 Unix Socket 而不是 TCP 端口。而默認情況下,Unix socket 屬于 root 用戶,因此需要root權限 才能訪問。

sudo groupadd docker? ? ? ? ? #添加docker用戶組

sudo gpasswd -a $XXX docker? #檢測當前用戶是否已經在docker用戶組中,其中XXX為用

戶名,例如我

sudo gpasswd -a blekey docker

sudo gpasswd -a $USER docker? #將當前用戶添加至docker用戶組

newgrp docker? ? ? ? ? ? ? ? #更新docker用戶組

需要生效的話需要重啟docker服務

systemctl restart docker

如果還不行檢查 /var/run/docker.sock?

如果是這種需要修改

chown root:docker docker.sock?

docker info? 出現?

WARNING: bridge-nf-call-iptables is disabled

WARNING: bridge-nf-call-ip6tables is disabled

解決辦法:

vi /etc/sysctl.conf

添加以下內容

net.bridge.bridge-nf-call-ip6tables = 1

net.bridge.bridge-nf-call-iptables = 1

最后再執行

sysctl -p

此時docker info就看不到此報錯了

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容