一,安装Docker-CE
本文采用阿里云提供的镜像站来安装
1,安装所需工具
[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
2,添加yum源
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
将下载到本地 /etc/yum.repos.d/ 下
3,更新并安装
[root@localhost ~]# yum makecache fast
[root@localhost ~]# yum -y install docker-ce
4,启动docker服务
[root@localhost ~]# systemctl start docker
检查是否正常安装:
yum list installed | grep docker
docker info
5,安装指定版本的docker-ce:
查看版本:
[root@localhost ~]# yum list docker-ce.x86_64 --showduplicates | sort -r
* updates: mirrors.tuna.tsinghua.edu.cn
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
Installed Packages
* extras: mirrors.tuna.tsinghua.edu.cn
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos @docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
* base: mirrors.tuna.tsinghua.edu.cn
Available Packages
安装指定版本
[root@localhost ~]# yum -y install docker-ce-17.12.0.ce-1.el7.centos
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
Package docker-ce-17.12.0.ce-1.el7.centos.x86_64 already installed and latest version
Nothing to do
6,查看安装docker信息
[root@localhost ~]# docker version
Client:
Version: 17.12.0-ce
API version: 1.35
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:10:14 2017
OS/Arch: linux/amd64
Server:
Engine:
Version: 17.12.0-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:12:46 2017
OS/Arch: linux/amd64
Experimental: false
7,测试docker
[root@localhost ~]#docker run hello-world
8,查看是否运行:
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest f2a91732366c 3 months ago 1.85kB
9,运行一个httpd镜像:
[root@localhost ~]# docker run -d -p 8088:80 httpd
Unable to find image 'httpd:latest' locally
latest: Pulling from library/httpd
4176fe04cefe: Downloading [=================> ] 18.73MB/52.61MB
d6c01cf91b98: Download complete
b7066921647a: Download complete
......
从 Docker Hub 下载 httpd 镜像。镜像中已经安装好了 Apache HTTP Server,并将容器的 80 端口映射到 host 的 8088 端口
然后访问:http://[hostIP:8088]
就可以看到效果了
二,如何卸载Docker-CE
1,查看是否已经安装的Docker软件包
yum list installed | grep docker
2,如果已安装不想要docker、docker-engine、docker-ce相关的软件包,则卸载掉
yum -y remove docker docker-common docker-selinux docker-engine docker-engine-selinux container-selinux docker-ce
3,删除所有的镜像、容器、数据卷、配置文件等
rm -rf /var/lib/docker
三,补充
解决国内获取docker镜像缓慢问题
一,中国科技大学开源镜像站:https://docker.mirrors.ustc.edu.cn
{"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]}
二,daemon.json 一些配置
{ //配置仓库镜像地址 "registry-mirrors": ["https://kzflb.mirror.aliyuncs.com"], //默认http私有仓库不能访问,设置后才可以 "insecure-registries": ["http://192.168.200.10"], //开启docker-API远程访问 "hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"] }