欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

docker环境部署系列(〇):docker安装

程序员文章站 2022-03-07 13:06:36
...

说明

此篇文章主要介绍docker的安装,docker使用的版本为v18.06,操作系统使用的版本为CentOS 7.5
安装时,需将用户切换到root用户,以下所有的操作均在root用户下进行。

安装

有网情况

  1. 安装前置内容
yum install -y yum-utils device-mapper-persistent-data lvm2
yum -y install vim-enhanced
  1. 添加软件源信息
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux    /centos/docker-ce.repo 
  1. 更新并安装docker-ce
yum makecache fast
yum -y install docker-ce
  1. 开启docker服务
systemctl start docker
  1. 可以使用docker version命令查看docker版本号,检查docker是否安装成功
  2. 设置开机自启动
systemctl enable docker.service 

无网情况

  1. 下载docker的安装包,点击此处下载安装包,建议下载docker-18.06.1-ce.tgz
  2. 上传docker-18.06.1-ce.tgz到目标服务器(假设将压缩包存放在:/root/docker)
  3. 切换到/root/docker,解缩docker-18.06.1-ce.tgz
cd /root/docker
tar -xvf docker-18.06.1-ce.tgz
  1. 复制docker目录下的文件到/usr/bin下
cp docker/* /usr/bin/
  1. 创建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
  1. 添加文件权限
chmod +x /etc/systemd/system/docker.service
  1. 重载daemon配置文件
systemctl daemon-reload
  1. 启动docker
systemctl start docker
  1. 设置开机自启动
systemctl enable docker.service
  1. 查看docker状态,验证安装是否成功
systemctl status docker
  • 提示以下内容代表docker安装成功
    docker环境部署系列(〇):docker安装
相关标签: docker学习 docker