本文共 8755 字,大约阅读时间需要 29 分钟。
yum install -y docker-io
[root@centos ~]# yum install -y docker-io已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.163.com * extras: mirrors.163.com * updates: mirrors.163.com正在解决依赖关系--> 正在检查事务---> 软件包 docker.x86_64.0.1.10.3-46.el7.centos.14 将被 安装--> 正在处理依赖关系 docker-common = 1.10.3-46.el7.centos.14,它被软件包 .....
docker version
Client: Version: 1.10.3 API version: 1.22 Package version: docker-common-1.10.3-46.el7.centos.14.x86_64 Go version: go1.6.3 Git commit: cb079f6-unsupported Built: Fri Sep 16 13:24:25 2016 OS/Arch: linux/amd64Server: Version: 1.10.3 API version: 1.22 Package version: docker-common-1.10.3-46.el7.centos.14.x86_64 Go version: go1.6.3 Git commit: cb079f6-unsupported Built: Fri Sep 16 13:24:25 2016 OS/Arch: linux/amd64
旧式语法
service docker start
centos7新式语法
systemctl start docker.service
旧式语法
chkconfig docker on
centos7新式语法
systemctl enable docker.service
当前新版本为1.13,默认安装好后启动失败。
如不想做过多设置,可以关闭selinux-enabled=false,就可以正常启动。 重新编辑docker配置文件: vi /etc/sysconfig/docker 找到以下这行 OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false' 将--selinux-enabled改为--selinux-enabled=false阿里云的介绍:
配置Docker加速器
您可以使用如下的脚本将mirror的配置添加到docker daemon的启动参数中。
系统要求 CentOS 7 以上,Docker 1.9 以上。 (其它linux请详见阿里云介绍)
sudo cp -n /lib/systemd/system/docker.service /etc/systemd/system/docker.service
sudo sed -i "s|ExecStart=/usr/bin/docker daemon|ExecStart=/usr/bin/docker daemon --registry-mirror=https://ir6ei990.mirror.aliyuncs.com|g" /etc/systemd/system/docker.service
sudo systemctl daemon-reload
sudo service docker restart
执行后不起作用,也许因为docker版本不一致,本人是手动修改成功的
找到这行
ExecStart=/usr/bin/docker-current daemon
将自己的加速地址加进去,最后修改为ExecStart=/usr/bin/docker-current daemon --registry-mirror=https://ir6ei990.mirror.aliyuncs.com
然后重启dockersystemctl daemon-reload
systemctl restart docker.service
docker pull busybox
Using default tag: latestTrying to pull repository docker.io/library/busybox ... latest: Pulling from docker.io/library/busybox56bec22e3559: Pull complete Digest: sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912Status: Downloaded newer image for docker.io/busybox:latest
docker images
REPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/busybox latest e02e811dd08f 4 weeks ago 1.093 MB
这就是刚才上面下载的busybox
docker run -d -it --name testbusybox busybox
44391ec69021707afbeba0c1dda7633c4b0507838fecdf37ae3ad56182754710
-d 后台启动
-i, --interactive Keep STDIN open even if not attached
-t, --tty Allocate a pseudo-TTY
进行交互式操作(例如Shell脚本),那我们必须使用-i -t参数同容器进行数据交互。但是当通过管道同容器进行交互时,就不需要使用-t参数
--name 容器名称(方便后续操作)
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8d713216033b busybox "sh" 5 minutes ago Up 5 minutes testbusybox
刚才启动的容器为后台运行。我们可以通过一下命令进入启动的容器中
docker exec -it testbusybox /bin/sh
/ # pwd// # lsbin dev etc home proc root run sys tmp usr var
exit
/ # / # exit[root@centos ~]#
docker restart testbusybox
[root@centos ~]# docker restart testbusyboxtestbusybox
docker stop testbusybox
[root@centos ~]# docker stop testbusybox testbusybox[root@centos ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
发现容器关闭后docker ps 命令看不到了,默认显示启动的容器,我们可以通过加-a参数来显示停止的docker容器
[root@centos ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8d713216033b busybox "sh" 22 hours ago Exited (137) About a minute ago testbusybox44391ec69021 busybox "sh" 22 hours ago Exited (137) 22 hours ago trusting_wright2810cbbefdbe busybox "sh" 22 hours ago Exited (0) 22 hours ago drunk_bellddf3b42c2970 c9bd19d022f6 "/entrypoint.sh /etc/" 2 days ago Exited (2) 2 days ago stoic_brattain
这些容器都是实际存在的。
以及启动成容器的镜像,无法再次run。除非删除容器后再run。
我们拿windows的ghost打比方: 镜像就是ghost光盘,容器就是已经装入电脑后的系统,ghost光盘可以为一台机器安装无限次,但是docker有点区别,已经装了A镜像的电脑,无法再次安装A的镜像。除非1:删除已安装的容器,再次run A镜像进行安装。
2:换一个容器名字[root@centos ~]# docker run -d -it --name testbusybox busyboxdocker: Error response from daemon: Conflict. The name "/testbusybox" is already in use by container 8d713216033bd01610aa444647ce971e9d47786c81637e12b5a85659d0006b63. You have to remove (or rename) that container to be able to reuse that name..See '/usr/bin/docker-current run --help'.
换了容器名后启动成功
[root@centos ~]# docker run -d -it --name testbusybox1 busybox3ec4539e98a82d07fa362c7d90ff1a27547130a642662a1b8904742ce4ed2419
docker rm -f testbusybox1
[root@centos ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES3ec4539e98a8 busybox "sh" 57 seconds ago Up 56 seconds testbusybox18d713216033b busybox "sh" 22 hours ago Exited (137) 11 minutes ago testbusybox44391ec69021 busybox "sh" 22 hours ago Exited (137) 22 hours ago trusting_wright2810cbbefdbe busybox "sh" 22 hours ago Exited (0) 22 hours ago drunk_bellddf3b42c2970 c9bd19d022f6 "/entrypoint.sh /etc/" 2 days ago Exited (2) 2 days ago stoic_brattain[root@centos ~]# [root@centos ~]# docker rm -f testbusybox1testbusybox1[root@centos ~]# docker rm -f testbusyboxtestbusybox[root@centos ~]# docker rm -f trusting_wrighttrusting_wright[root@centos ~]# docker rm -f drunk_belldrunk_bell[root@centos ~]# docker rm -f stoic_brattainstoic_brattain[root@centos ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker tag busybox registry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox:1.0.0docker imagesdocker.io/busybox latest e02e811dd08f 4 weeks ago 1.093 MBregistry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox 1.0.0 e02e811dd08f 4 weeks ago 1.093 MB
将busybox修改为
registry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox:1.0.0前面已经修改了对应的阿里云仓库名/镜像名:Tag
推送的时候就会发送到registry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox这个仓库中去。
具体阿里云docker镜像仓库可以自行查阅阿里云docker的帮助文档,很简单的。
发送前需要登录阿里云docker仓库
docker login --username=wzgdxg registry.cn-hangzhou.aliyuncs.com
Password: WARNING: login credentials saved in /root/.docker/config.jsonLogin Succeeded
推送
docker push registry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox:1.0.0
The push refers to a repository [registry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox]e88b3f82283b: Pushed 1.0.0: digest: sha256:9393222c6789842b16bcf7306b6eb4b486d81a48d3b8b8f206589b5d1d5a6101 size: 505
docker rmi -f registry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox:1.0.0
Untagged: registry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox:1.0.0[root@centos ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/busybox latest e02e811dd08f 4 weeks ago 1.093 MB
docker pull registry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox:1.0.0
Trying to pull repository registry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox ... 1.0.0: Pulling from registry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusyboxDigest: sha256:9393222c6789842b16bcf7306b6eb4b486d81a48d3b8b8f206589b5d1d5a6101Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox:1.0.0[root@centos ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/busybox latest e02e811dd08f 4 weeks ago 1.093 MBregistry.cn-hangzhou.aliyuncs.com/wzgdxg/testbusybox 1.0.0 e02e811dd08f 4 weeks ago 1.093 MB
转载地址:http://imbab.baihongyu.com/