1. 程式人生 > 其它 >如何在 Ubuntu 20.04 上安裝和使用 Docker(安裝包)

如何在 Ubuntu 20.04 上安裝和使用 Docker(安裝包)

Linux Docker

如何在 Ubuntu 20.04 上安裝和使用 Docker

安裝前將所有的軟體包上傳到系統的/opt路徑,所有的操作都在/opt目錄下

一、解壓檔案

tar -xzvf docker-19.03.0.tgz

二、拷貝解壓後的檔案到/usr/bin/下面

cp docker/* /usr/bin/

三、加入系統檔案

cat >/etc/systemd/system/docker.service <<-EOF
[Unit]
Description=Docker Application Container Engine
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 -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
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
EOF

四、啟動Docker

systemctl daemon-reload && systemctl start docker && systemctl enable docker.service

五、Docker配置檔案

編輯daemon.json檔案輸入以下內容

vim /etc/docker/daemon.json
{
    "log-driver":"json-file",
    "log-opts":{
        "max-size" :"10m","max-file":"4"
    },
    "registry-mirrors": ["https://6kx4zyno.mirror.aliyuncs.com"]
}

六、重啟Docker

systemctl restart docker 

七、檢查Docker是否安裝成功

docker --version

八、總結

我們已經向你展示如何在 Ubuntu 20.04 機器上安裝 Docker。

想要學習更多關於 Docker 的資訊,查閱官方 Docker 文件