1 环境介绍
版本信息:
[root@localhost]# cat /proc/version
Linux version 3.10.0-514.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Nov 22 16:42:41 UTC 2016
[root@localhost jenkins]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
# Centos系统是离线的,但是可以通过代理访问网络,否则,就无法pull Image了.
# 查看yum list中是否有docker安装包:
[root@localhost home]# yum list | grep docker
docker.x86_64 2:1.12.6-32.git88a4867.el7.centos
docker-client.x86_64 2:1.12.6-32.git88a4867.el7.centos
docker-common.x86_64 2:1.12.6-32.git88a4867.el7.centos
…
[root@localhost home]#
2安装Docker
# install
sudo yum install -y docker.x86_64
# yum install docker
# 查看docker是否安装成功
docker --version
# 开机自启动, 好像开机启动并不是很灵
sudo chkconfig docker on
# 查看docker daemon是否在运行
ps aux | grep docker
3设置代理
# following link is to resolve docker-runc not found issue,proxy is not necessary *#
ln -s /usr/libexec/docker/docker-proxy-current /usr/bin/docker-proxy
ln -s /usr/libexec/docker/docker-runc-current /usr/bin/docker-runc
#停止docker service(设置代理前,需要停止)
service docker stop
# 设置代理, 成功后,会自动启动docker service
sudo HTTP_PROXY=http://ip:port /usr/bin/dockerd --userland-proxy=false &
4 Docker Service
# 启动Docker Service
# 注: 设置代理时,Docker Service会自动启动
service docker start
# 或者这种启动方式
systemctl start docker.service
#停止docker service(设置代理前,需要停止)
service docker stop
# 或者这种停止方式
systemctl stop docker.service
# 查看服务状态
systemctl status docker.service
# 查看docker daemon是否在运行
ps aux | grep docker
5 Image
# 下载Image, 默认从docker.io下载,速度会比较慢
# 可以从daocloud.io中下载,速度会快一些.
# 我在公司, Centos上感觉不明显, 在家里用ubuntu感觉特别明显
docker pull centos
# 查询仓库中的Image
# --automated=false: 仅显示自动创建的镜像
# --no-trunc=false: 不截断显示
# -s, --starts=0: 指定星级以上
docker search -s 10 centos
# 查询本地Image
docker images
# 删除Image
docker rmi docker.io/Ubuntu
6 运行Image
# 运行Image
# 注意: 运行Image时, 需要关闭代理,重启docker service,
# 否则会遇到错误:container_linux.go:247: starting container process caused
# "process_linux.go:334: running prestart hook 1 caused "error running hook: exit status 1, stdout: , stderr: ""
# /usr/bin/docker-current: Error response from daemon: invalid header field value "oci runtime error:
# container_linux.go:247: starting container process caused "process_linux.go:334:
# running prestart hook 1 caused \"error running hook: exit status 1, stdout: , stderr: \"" ".
# 方式1
sudo docker run centos /bin/echo 'Hello World'
# 带调试信息
sudo docker --debug=true run centos /bin/echo 'Hello World'
#方式2
[root@localhost home]# docker create centos
3e8185a9fb586e1b3f12fb1c69c2a22225df1e5505c9315e3b62743d489d2904
# 查看容器信息
[root@localhost home]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3e8185a9fb58 centos "/bin/bash" 5 seconds ago Created gigantic_franklin
[root@localhost home]# docker start 3e8185a9fb58
docker run -idt --name pcta-demon matthewx:pcta-matthewx
# 进入容器
docker attach pcta-demon
# 删除容器
docker rm 3e8185a9fb58
7 卸载Docker
#centos卸载
yum list installed | grep docker
yum -y remove docker.x86_64
yum -y remove docker-client.x86_64
yum -y remove docker-common.x86_64
# 如果/var/lib/docker删除失败,
# 请使用lsof |grep docker看看有哪些进程在使用,kill掉这些进程.
# 此处删除应该是删除pull的image等,所以也可以不删除.
rm -rf /var/lib/docker
lsof |grep docker