docker环境部署系列(〇):docker安装
程序员文章站
2022-03-07 13:06:36
...
说明
此篇文章主要介绍docker的安装,docker使用的版本为v18.06
,操作系统使用的版本为CentOS 7.5
。
安装时,需将用户切换到root用户,以下所有的操作均在root用户下进行。
安装
有网情况
- 安装前置内容
yum install -y yum-utils device-mapper-persistent-data lvm2
yum -y install vim-enhanced
- 添加软件源信息
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux /centos/docker-ce.repo
- 更新并安装docker-ce
yum makecache fast
yum -y install docker-ce
- 开启docker服务
systemctl start docker
- 可以使用
docker version
命令查看docker版本号,检查docker是否安装成功 - 设置开机自启动
systemctl enable docker.service
无网情况
- 下载docker的安装包,点击此处下载安装包,建议下载docker-18.06.1-ce.tgz
- 上传docker-18.06.1-ce.tgz到目标服务器(假设将压缩包存放在:/root/docker)
- 切换到/root/docker,解缩docker-18.06.1-ce.tgz
cd /root/docker
tar -xvf docker-18.06.1-ce.tgz
- 复制docker目录下的文件到/usr/bin下
cp docker/* /usr/bin/
- 创建docker的配置文件,并写入配置内容
vim /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
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
- 添加文件权限
chmod +x /etc/systemd/system/docker.service
- 重载daemon配置文件
systemctl daemon-reload
- 启动docker
systemctl start docker
- 设置开机自启动
systemctl enable docker.service
- 查看docker状态,验证安装是否成功
systemctl status docker
- 提示以下内容代表docker安装成功
下一篇: Dockerfile解析