Centos7安装和卸载docker-ce

docker所需环境准备

系统要求CentOS 7.X 以上版本,内核至少3.10,64-bit

uname -r   //查看内核 


3.10.0-327.el7.x86_64 


yum update   //升级本地yum包 

创建docker的yum库

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

 

安装docker

yum -y install docker-ce

启动docker服务并设置开机自动启动

systemctl start docker.service 


systemctl enable docker.service 


Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. 


设置镜像 

vi /etc/docker/daemon.json

{
  "registry-mirrors": ["https://aj2rgad5.mirror.aliyuncs.com"]
}

配置 DOCKER_HOST

vim /etc/profile.d/docker.sh

内容如下

export DOCKER_HOST=tcp://localhost:2375 

应用

source /etc/profile
source /etc/bashrc

配置启动文件

sudo vim /lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd

修改为

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock -H tcp://0.0.0.0:7654


  2375 是管理端口 
  7654 是备用端口


重载配置和重启

sudo systemctl daemon-reload 
sudo systemctl restart docker.service

查看

docker version

输出

Client:
 Version:      18.03.1-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   9ee9f40
 Built:        Thu Apr 26 07:20:16 2018
 OS/Arch:      linux/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.03.1-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Thu Apr 26 07:23:58 2018
  OS/Arch:      linux/amd64
  Experimental: false

测试docker是否正常安装和运行

docker run hello-world

卸载


1.查询安装过的包
yum list installed | grep docker
docker-engine.x86_64                 17.03.0.ce-1.el7.centos         @dockerrepo
2.删除安装的软件包
yum -y remove docker-engine.x86_64

异常问题

Centos7.x 执行 docker 时报如下错误 
出现以下错误

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Cannot connect to the Docker daemon at tcp://localhost:2373. Is the docker daemon running?

检查配置 DOCKER_HOST和配置启动文件

你可能感兴趣的:(环境部署)