https://linux.cn/article-4340-1.htmlhtml
Docker 软件包已经包括在默认的 CentOS-Extras 软件源里。所以想要安装 docker,只须要运行下面的 yum 命令:python
- [root@localhost ~]# yum install docker
安装完成后,使用下面的命令来启动 docker 服务,并将其设置为开机启动:linux
- [root@localhost ~]# service docker start
- [root@localhost ~]# chkconfig docker on
(LCTT 译注:此处采用了旧式的 sysv 语法,如采用CentOS 7中支持的新式 systemd 语法,以下:docker
- [root@localhost ~]# systemctl start docker.service
- [root@localhost ~]# systemctl enable docker.service
)ubuntu
下载官方的 CentOS 镜像到本地 (LCTT 译注:因为 Docker 被墙 :-< ,因此请使用 http://docker.cn 的镜像,感谢 @马全一 的镜像。 )centos
- [root@localhost ~]# docker pull centos
- Pulling repository centos
- 192178b11d36: Download complete
- 70441cac1ed5: Download complete
- ae0c2d0bdc10: Download complete
- 511136ea3c5a: Download complete
- 5b12ef8fd570: Download complete
确认 CentOS 镜像已经被获取:bash
- [root@localhost ~]# docker images centos
- REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
- centos centos5 192178b11d36 2 weeks ago 466.9 MB
- centos centos6 70441cac1ed5 2 weeks ago 215.8 MB
- centos centos7 ae0c2d0bdc10 2 weeks ago 224 MB
- centos latest ae0c2d0bdc10 2 weeks ago 224 MB
运行一个 Docker 容器:python2.7
- [root@localhost ~]# docker run -i -t centos /bin/bash
- [root@dbf66395436d /]#
咱们能够看到,CentOS 容器已经被启动,而且咱们获得了 bash 提示符。在 docker 命令中咱们使用了 “-i 捕获标准输入输出”和 “-t 分配一个终端或控制台”选项。若要断开与容器的链接,输入 exit。ui
- [root@cd05639b3f5c /]# cat /etc/redhat-release
- CentOS Linux release 7.0.1406 (Core)
- [root@cd05639b3f5c /]# exit
- exit
- [root@localhost ~]#
咱们还能够搜索基于 Fedora 和 Ubuntu 操做系统的容器。centos7
- [root@localhost ~]# docker search ubuntu
- [root@localhost ~]# docker search fedora
显示当前正在运行容器的列表
虽然很简单,仍是有URL确认,x权限设定等须要作,若是使用pip进行安装虽然看似绕远,实质上也是绕远,安装来一看吧。CentOS上须要先行安装yum的一个额外的包,这个包里面才有python-pip,缺省的没有。
[root@host32 ~]# yum -y install epel-release
[root@host32 ~]# yum -y install python-pip
确认版本
[root@host32 ~]# pip --version
pip 7.1.0 from /usr/lib/python2.7/site-packages (python 2.7)
接下来就是安装docker-compose[root@host32 ~]# pip install docker-compose
[root@bogon bin]# docker-compose version
docker-compose version 1.15.0, build e12f3b9
docker-py version: 2.4.2
CPython version: 2.7.5