Options: --add-host list Add a custom host-to-IP mapping (host:ip) -a, --attach list Attach to STDIN, STDOUT or STDERR --blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0) --blkio-weight-device list Block IO weight (relative device weight) (default []) --cap-add list Add Linux capabilities ...
//查看docker本地所有容器,注意状态为Created [root@xxx /]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d26cbeecf22d registry.cn-hangzhou.aliyuncs.com/xym/163ubuntu:14.04 "/bin/sh -c '/usr/sb…" 8 seconds ago Created practical_wright
//查看docker本地所有容器,注意状态为Up [root@xxx /]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d26cbeecf22d registry.cn-hangzhou.aliyuncs.com/xym/163ubuntu:14.04 "/bin/sh -c '/usr/sb…" 41 seconds ago Up 2 seconds practical_wright
//查看本地所有Docker容器,注意状态为Exited [root@xxx /]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d26cbeecf22d registry.cn-hangzhou.aliyuncs.com/xym/163ubuntu:14.04 "/bin/sh -c '/usr/sb…" 14 minutes ago Exited (137) 5 seconds ago practical_wright
//查看本地所有Docker容器,注意状态为Up [root@xxx /]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d26cbeecf22d registry.cn-hangzhou.aliyuncs.com/xym/163ubuntu:14.04 "/bin/sh -c '/usr/sb…" 14 minutes ago Up 2 seconds
//创建容器并执行一个输出命令 [root@xxx /]# docker run ubuntu:latest /bin/echo "Hello World" Hello World
//查看本地所有Docker容器,注意状态为Exited [root@xxx /]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3fa47db4c105 ubuntu:latest "/bin/echo 'Hello Wo…" 8 seconds ago Exited (0) 7 seconds ago elated_goldwasser
//终止前 [root@xxx ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5d4cfe5b4b61 ubuntu:latest "/bin/sh -c 'while t…" 16 minutes ago Up 16 minutes thirsty_lewin
//发送终止命令 [root@xxx ~]# docker stop 5d4c 5d4c
//终止后状态为Exited [root@xxx ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5d4cfe5b4b61 ubuntu:latest "/bin/sh -c 'while t…" 18 minutes ago Exited (137) 56 seconds ago thirsty_lewin
//查看运行容器 [root@xxx ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
//重启容器 [root@xxx ~]# docker restart 5d4c 5d4c
//查看运行容器 [root@xxx ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5d4cfe5b4b61 ubuntu:latest "/bin/sh -c 'while t…" 25 minutes ago Up 1 second thirsty_lewin
[root@xxx ~]# docker run -itd ubuntu /bin/bash 3535fd6c5ccab3c4d4737c1385ac18c36bd190c129c70c664fbf8c62a1707e67 [root@xxx ~]# docker attach 3535 root@3535fd6c5cca:/# root@3535fd6c5cca:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
Options: -d, --detach 以后台模式运行命令 --detach-keys string Override the key sequence for detaching a container -e, --env list 设置环境变量 -i, --interactive 打开标准输入接受用户输入命令,默认为false --privileged Give extended privileges to the command -t, --tty 分配一个伪终端,默认为false -u, --user string 执行命令的用户名或ID -w, --workdir string Working directory inside the container
[root@xxx ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5d4cfe5b4b61 ubuntu:latest "/bin/sh -c 'while t…" About an hour ago Up About a minute thirsty_lewin
//查看运行容器 [root@xxx ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5d4cfe5b4b61 ubuntu:latest "/bin/sh -c 'while t…" About an hour ago Up 4 minutes thirsty_lewin
//查看运行中的容器 [root@xxx ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5d4cfe5b4b61 ubuntu:latest "/bin/sh -c 'while t…" About an hour ago Up 14 minutes thirsty_lewin
//删除运行状态的容器 [root@xxx ~]# docker rm 5d4c Error response from daemon: You cannot remove a running container 5d4cfe5b4b6109fd8df8717fcd87790e7692f70d7e8e8d7590ba4c269f6dd717. Stop the container before attempting removal or force remove
[root@xxx ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE xym/ubuntu 1.0 f916030e78e9 2 seconds ago 85.8MB centos-7 import be5e039acd03 19 hours ago 435MB