linux 安裝docker


1、安裝環境

此處在Centos7進行安裝,可以使用以下命令查看CentOS版本

lsb_release -a

在 CentOS 7安裝docker要求系統為64位、系統內核版本為 3.10 以上,可以使用以下命令查看

uname -r

2、用yum源安裝

2.1 查看是否已安裝docker列表

yum list installed | grep docker

2.2 安裝docker

yum -y install docker

-y表示不詢問安裝,直到安裝成功,安裝完后再次查看安裝列表

2.3 啟動docker

systemctl start docker

2.4 查看docker服務狀態

systemctl status docker

以上說明docker安裝成功

3、離線安裝模式

3.1 安裝包官方地址https://download.docker.com/linux/static/stable/x86_64/

可以先下載到本地,然后通過ftp工具上傳到服務器上,或者在服務器上使用命令下載

wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz

3.2 解壓

tar -zxvf docker-18.06.3-ce.tgz

3.3 將解壓出來的docker文件復制到 /usr/bin/ 目錄下

cp docker/* /usr/bin/

3.4 在/etc/systemd/system/目錄下新增docker.service文件,內容如下,這樣可以將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 --selinux-enabled=false --insecure-registry=127.0.0.1
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

此處的--insecure-registry=127.0.0.1(此處改成你私服ip)設置是針對有搭建了自己私服Harbor時允許docker進行不安全的訪問,否則訪問將會被拒絕。

3.5 啟動docker

給docker.service文件添加執行權限

chmod +x /etc/systemd/system/docker.service 

重新加載配置文件(每次有修改docker.service文件時都要重新加載下)

systemctl daemon-reload                

啟動

systemctl start docker

設置開機啟動

systemctl enable docker.service

查看docker服務狀態

systemctl status docker

上圖表示docker已安裝成功

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM