标签:ble color val dev star nod ted war container
1.docker create创建一个容器,但容器并没启动,就和我们创建虚拟机一样,创建了虚拟机后没启动
[root@centos-02 ~]# docker create -it centos6 bash
WARNING: IPv4 forwarding is disabled. Networking will not work.
558e31f7b0fb941ca4ee8c1c2b42553b06ac79c0613984b7ad8b9b4ba97f61fd
[root@centos-02 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
558e31f7b0fb centos6 "bash" 9 seconds ago Created hopeful_murdock
94b9eab05296 centos6 "bash" About an hour ago Up About an hour elegant_minsky
815adfd9da61 centos "/bin/bash" 3 days ago Up 3 days distracted_mahavira
[root@centos-02 ~]#
2.启动容器
[root@centos-02 ~]# docker start 558e31f7b0fb
558e31f7b0fb
[root@centos-02 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
558e31f7b0fb centos6 "bash" 2 minutes ago Up 8 seconds hopeful_murdock
94b9eab05296 centos6 "bash" 2 hours ago Up About an hour elegant_minsky
815adfd9da61 centos "/bin/bash" 3 days ago Up 3 days distracted_mahavira
[root@centos-02 ~]#
3.不加-d运行容器
[root@centos-02 ~]# docker run -it centos bash WARNING: IPv4 forwarding is disabled. Networking will not work. [root@f4eba170402c /]# ls bin etc lib media opt root sbin sys usr dev home lib64 mnt proc run srv tmp var
4.我们用ctrl+d退出,然后查看容器发现没有f4eba170402c,因为我们退出了之前的bash,这是因为我们退出了没有加-d,加上-a参数查看状态为Exited,
[root@f4eba170402c /]# exit [root@centos-02 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 558e31f7b0fb centos6 "bash" 10 minutes ago Up 7 minutes hopeful_murdock 94b9eab05296 centos6 "bash" 2 hours ago Up 2 hours elegant_minsky 815adfd9da61 centos "/bin/bash" 3 days ago Up 3 days distracted_mahavira [root@centos-02 ~]#
[root@centos-02 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f4eba170402c centos "bash" 3 minutes ago Exited (0) 2 minutes ago cocky_bell
558e31f7b0fb centos6 "bash" 12 minutes ago Up 9 minutes hopeful_murdock
94b9eab05296 centos6 "bash" 2 hours ago Up 2 hours elegant_minsky
815adfd9da61 centos "/bin/bash" 3 days ago Up 3 days distracted_mahavira
[root@centos-02 ~]#
5.给容器起个名字
[root@centos-02 ~]# docker run -itd --name centos6_1 centos6 bash
WARNING: IPv4 forwarding is disabled. Networking will not work.
5e32153dbbd6dea32b62291f9aa484b1d82c84d5edf9899ab72a8335f61e16ac
[root@centos-02 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e32153dbbd6 centos6 "bash" 15 seconds ago Up 11 seconds centos6_1
558e31f7b0fb centos6 "bash" 17 minutes ago Up 14 minutes hopeful_murdock
94b9eab05296 centos6 "bash" 2 hours ago Up 2 hours elegant_minsky
815adfd9da61 centos "/bin/bash" 3 days ago Up 3 days distracted_mahavira
[root@centos-02 ~]#
6.可以直接用名字进入容器
[root@centos-02 ~]# docker exec -it centos6_1 bash [root@5e32153dbbd6 /]#
7.容器执行完直接删除、命令执行完容器就退出,执行完不留任何痕迹。
[root@centos-02 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5e32153dbbd6 centos6 "bash" 5 minutes ago Up 5 minutes centos6_1 558e31f7b0fb centos6 "bash" 22 minutes ago Up 19 minutes hopeful_murdock 94b9eab05296 centos6 "bash" 2 hours ago Up 2 hours elegant_minsky 815adfd9da61 centos "/bin/bash" 3 days ago Up 3 days distracted_mahavira [root@centos-02 ~]# docker run --rm -it centos bash -c "sleep 10" WARNING: IPv4 forwarding is disabled. Networking will not work. [root@centos-02 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5e32153dbbd6 centos6 "bash" 7 minutes ago Up 6 minutes centos6_1 f4eba170402c centos "bash" 15 minutes ago Exited (0) 13 minutes ago cocky_bell 558e31f7b0fb centos6 "bash" 23 minutes ago Up 21 minutes hopeful_murdock 94b9eab05296 centos6 "bash" 2 hours ago Up 2 hours elegant_minsky 815adfd9da61 centos "/bin/bash" 3 days ago Up 3 days distracted_mahavira [root@centos-02 ~]#
1.docker logs查看容器运行历史信息
[root@centos-02 ~]# docker run -itd centos bash -c "echo 123" WARNING: IPv4 forwarding is disabled. Networking will not work. 59e0b06bcfb4e407ba29719e0bd805c8f52948429ecfbf94c8616ea5090dcd37 [root@centos-02 ~]# docker logs 59e0b0 123 [root@centos-02 ~]#
2.删除容器 rm,删除一个启动的容器加-f参数
[root@centos-02 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 59e0b06bcfb4 centos "bash -c ‘echo 123‘" 2 minutes ago Exited (0) 2 minutes ago xenodochial_hoover 5e32153dbbd6 centos6 "bash" 18 minutes ago Up 18 minutes centos6_1 f4eba170402c centos "bash" 26 minutes ago Exited (0) 24 minutes ago cocky_bell 558e31f7b0fb centos6 "bash" 34 minutes ago Up 32 minutes hopeful_murdock 94b9eab05296 centos6 "bash" 2 hours ago Up 2 hours elegant_minsky 815adfd9da61 centos "/bin/bash" 3 days ago Up 3 days distracted_mahavira [root@centos-02 ~]# docker rm 59e0b06bcfb4 59e0b06bcfb4 [root@centos-02 ~]# docker rm f4eba170402c f4eba170402c [root@centos-02 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5e32153dbbd6 centos6 "bash" 20 minutes ago Up 20 minutes centos6_1 558e31f7b0fb centos6 "bash" 37 minutes ago Up 34 minutes hopeful_murdock 94b9eab05296 centos6 "bash" 2 hours ago Up 2 hours elegant_minsky 815adfd9da61 centos "/bin/bash" 3 days ago Up 3 days distracted_mahavira [root@centos-02 ~]#
[root@centos-02 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5e32153dbbd6 centos6 "bash" 21 minutes ago Up 21 minutes centos6_1 558e31f7b0fb centos6 "bash" 38 minutes ago Up 35 minutes hopeful_murdock 94b9eab05296 centos6 "bash" 2 hours ago Up 2 hours elegant_minsky 815adfd9da61 centos "/bin/bash" 3 days ago Up 3 days distracted_mahavira [root@centos-02 ~]# docker rm 558e31f7b0fb Error response from daemon: You cannot remove a running container 558e31f7b0fb941ca4ee8c1c2b42553b06ac79c0613984b7ad8b9b4ba97f61fd. Stop the container before attempting removal or
force remove [root@centos-02 ~]# docker rm -f 558e31f7b0fb 558e31f7b0fb [root@centos-02 ~]#
[root@centos-02 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5e32153dbbd6 centos6 "bash" 22 minutes ago Up 22 minutes centos6_1 94b9eab05296 centos6 "bash" 2 hours ago Up 2 hours elegant_minsky 815adfd9da61 centos "/bin/bash" 3 days ago Up 3 days distracted_mahavira [root@centos-02 ~]#
1.用registry镜像搭建私有仓库
标签:ble color val dev star nod ted war container
原文地址:https://www.cnblogs.com/sunyujun/p/9208208.html