目录

docker安装和卸载

docker安装和卸载

服务器系统:Ubuntu Server 18.04.2 64bit

1 安装docker:

1.1 在线安装

1.# yum install docker

1.2 离线安装

1.# docker-18.03.1-ce.tgz

1.2.1 解压

1.2.2 将解压出来的docker文件内容移动到 /usr/bin/ 目录下

1.2.3 docker注册为service

编辑/usr/lib/systemd/system/docker.service即可使用service docker restart/stop 等操作来启停docker

复制以下代码黏贴到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

1.2.4 启动 添加文件权限并启动docker

1.# chmod +x /usr/lib/systemd/system/docker.service

2.# systemctl daemon-reload

3.# systemctl start docker

4.# systemctl enable docker.service

1.2.5 验证

1.# systemctl status docker

2.# docker -v

3.# docker images

4.# docker ps -a

5.# docker info

1.3 使用docker

1.3.1 启动docker

1.设置docker开机启动

2.# systemctl enable docker

3.启动docker

4.# systemctl start docker

1 卸载docker:

yum remove docker-ce

rm -rf /var/lib/docker