[root@xaviyunserver ~]# docker create -it centos7 bash
5ab8830ee5d2cb4da2df86912275fc14806cad1f44bb24e0e54ddefa11a60532
[root@xaviyunserver ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5ab8830ee5d2 centos7 "bash" 10 seconds ago Created //创建 goofy_knuth
410e90b34976 centos7 "bash" 2 hours ago Up 2 hours dreamy_chatterjee
83a4c32c03ca centos "/bin/bash" 4 hours ago Up 4 hours nostalgic_lamport 启动容器:docker start CONTAINERID,启动容器后,可以使用 docker ps 查看到,有start 就有stop,和restart
之前我们使用的docker run 相当于先create再start
[root@xaviyunserver ~]# docker start 5ab8830ee5d2
5ab8830ee5d2
[root@xaviyunserver ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5ab8830ee5d2 centos7 "bash" 2 minutes ago Up 5 seconds goofy_knuth
410e90b34976 centos7 "bash" 2 hours ago Up 2 hours dreamy_chatterjee
83a4c32c03ca centos "/bin/bash" 4 hours ago Up 4 hours nostalgic_lamport 当执行如下(不带 -d 参数):docker run -it centos bash //当你退出时,这个容器也会显示退出的状态!
[root@xaviyunserver ~]# docker run -it centos bash
[root@27096b136e00 /]# ls
bin dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@27096b136e00 /]# ifconfig
bash: ifconfig: command not found //这里没有安装net-tool工具
让容器在后台运行:docker run -d
比如:
shell脚本:docker run -d centos bash -c "while :; do echo "123"; sleep 2; done"
–name 给容器自定义名字:docker run -itd --name centos7_1 centos7 bash
[root@xaviyunserver ~]# docker run -itd --name centos7_1 centos7 bash
1a93298ed9db13673049b2d8d82013aa2b8e98caaa36c4d771337fc3f9bc2cea
[root@xaviyunserver ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1a93298ed9db centos7 "bash" 4 seconds ago Up 4 seconds centos7_1
5ab8830ee5d2 centos7 "bash" 10 minutes ago Up 8 minutes goofy_knuth
410e90b34976 centos7 "bash" 2 hours ago Up 2 hours dreamy_chatterjee
83a4c32c03ca centos "/bin/bash" 4 hours ago Up 4 hours nostalgic_lamport 下次我们就可以直接使用名称进入:docker exec -it centos7_1 bash
[root@xaviyunserver ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
87517b62936d registry "/entrypoint.sh /etc…" 18 minutes ago Up 18 minutes 0.0.0.0:5000->5000/tcp friendly_davinci
1a93298ed9db centos7 "bash" 11 hours ago Up 11 hours centos7_1
5ab8830ee5d2 centos7 "bash" 11 hours ago Up 11 hours goofy_knuth
410e90b34976 centos7 "bash" 13 hours ago Up 13 hours dreamy_chatterjee
83a4c32c03ca centos "/bin/bash" 15 hours ago Up 15 hours nostalgic_lamport
访问:
[root@xaviyunserver ~]# telnet 127.0.0.1 5000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
[root@xaviyunserver ~]# curl 127.0.0.1:5000/v2/_catalog
{"repositories":[]}
上传一个镜像到私有库的步骤:
第一步:打标签:docker tag centos7 116.62.212.186:5000/centos7 //标记一下tag,必须要带有私有仓库的ip:port
[root@xaviyunserver ~]# docker tag centos7 116.62.212.186:5000/centos7
[root@xaviyunserver ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7 latest 1513b3b29ff7 14 hours ago 435MB
116.62.212.186:5000/centos7 latest 1513b3b29ff7 14 hours ago 435MB
centos_with_net latest 097367cfbba8 15 hours ago 282MB
ubuntu latest 113a43faa138 4 weeks ago 81.2MB
xavilinux_centos latest 49f7960eb7e4 4 weeks ago 200MB
centos latest 49f7960eb7e4 4 weeks ago 200MB
registry latest d1fd7d86a825 5 months ago 33.3MB
第二步,更改配置文件vi /etc/docker/daemon.json //更改为
[root@xaviyunserver ~]# vi /etc/docker/daemon.json
{
"insecure-registries": ["116.62.212.186:5000"]
}
[root@xaviyunserver ~]# systemctl restart docker //重启服务
[root@xaviyunserver ~]# docker ps -a //查看容器已经关闭,还需要启动
[root@xaviyunserver ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
87517b62936d registry "/entrypoint.sh /etc…" About an hour ago Exited (2) 3 minutes ago friendly_davinci
再次开启容器:docker start id //这里的id为 registry 容器id
[root@xaviyunserver ~]# docker start 87517b62936d
87517b62936d
[root@xaviyunserver ~]# docker push 116.62.212.186:5000/centos7
The push refers to repository [116.62.212.186:5000/centos7]
[root@xaviyunserver ~]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
Digest: sha256:43ed4f8c9d1695e97a39cdfe9475af9096e3723cfb79d820d8da00d61a277a85
Status: Image is up to date for mysql:latest
[root@xavi ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
43e7d37d1adc centos7 "bash" 13 minutes ago Up 13 minutes friendly_visvesvaraya
9c2b897587c2 registry "/entrypoint.sh /etc…" About an hour ago Up About an hour 0.0.0.0:2000->2000/tcp, 5000/tcp epic_saha
d0b81c693cc5 registry "/entrypoint.sh /etc…" About an hour ago Up About an hour 0.0.0.0:5000->5000/tcp objective_chebyshev docker run -itd --volumes-from friendly_visvesvaraya centos7 bash//这样,我们使用centos7镜像创建了新的容器,并且使用了friendly_visvesvaraya 容器的数据卷