CentOS 7 Docker 安装

环境: CnetOS 7.6


1.Docker 安装
  • 卸载旧版本
yum remove docker docker-client \
docker-client-latest  docker-common \
docker-latest  docker-latest-logrotate \
docker-logrotate  docker-selinux \
docker-engine-selinux  docker-engine
  • 安装依赖组件
sudo yum install -y yum-utils \
device-mapper-persistent-data  lvm2
  • 添加yum源
sudo yum-config-manager --add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
  • 安装docker
yum -y install docker-ce
  • 启动docker
# 设置docker开机自启动
systemctl enable docker     
systemctl start docker
  • 验证安装是否成功
docker version

显示如下证明安装启动成功:

Client: Docker Engine - Community
 Version:           19.03.1
 API version:       1.40
 Go version:        go1.12.5
 Git commit:        74b1e89
 Built:             Thu Jul 25 21:21:07 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.1
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.5
  Git commit:       74b1e89
  Built:            Thu Jul 25 21:19:36 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.6
  GitCommit:        894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc:
  Version:          1.0.0-rc8
  GitCommit:        425e105d5a03fabd737a126ad93d62a9eeede87f
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
  • 配置加速器
vi /etc/docker/daemon.json    #修改配置

添加如下配置:

{
    "registry-mirrors": ["https://tueulghe.mirror.aliyuncs.com","https://registry.docker-cn.com","http://hub-mirror.c.163.com","https://docker.mirrors.ustc.edu.cn"]
}

docker官方国内镜像源
https://registry.docker-cn.com
网易docker源
http://hub-mirror.c.163.com
中科大docker源
https://docker.mirrors.ustc.edu.cn
阿里云镜像加速器(需前往控制台自行配置)
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

  • 开启docker远程访问
vi /usr/lib/systemd/system/docker.service    #修改docker服务配置文件

修改如下:

# 在ExecStart=/usr/bin/dockerd 后添加
-H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

:wq 保存退出

systemctl daemon-reload      #重新载入配置
systemctl restart docker     #重启docker
  • 开放2375端口
vi /etc/sysconfig/iptables

添加如下规则

-A INPUT -p tcp -m state --state NEW -m tcp --dport 2375 -j ACCEPT

:wq 保存退出

# 重启iptables服务使规则配置生效
systemctl restart iptables.service 
2.Docker-compose安装
  • 下载docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  • 对文件添加可执行权限
sudo chmod +x /usr/local/bin/docker-compose
  • 验证安装是否成功
docker-compose --version

显示如下说明安装成功:

docker-compose version 1.24.1, build 4667896b

你可能感兴趣的:(CentOS 7 Docker 安装)