root@jimo-VirtualBox:~# docker run ubuntu pwd / root@jimo-VirtualBox:~#
查看容器运行状态:发现并没运行,而是一闪而过.
1 2 3 4 5 6
root@jimo-VirtualBox:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
root@jimo-VirtualBox:~# docker container ls -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 524c62fc3f68 ubuntu "pwd" About a minute ago Exited (0) About a minute ago pensive_khorana
root@jimo-VirtualBox:/home/jimo# docker run ubuntu /bin/bash -c "while true ; do sleep 1; done" # 另一终端 root@jimo-VirtualBox:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 549aa9db3954 ubuntu "/bin/bash -c 'while…" 36 seconds ago Up 34 seconds elastic_cray
-d参数: 后台运行. –name : 指定名字,不指定会随机分配. 如下:
1 2 3 4 5
root@jimo-VirtualBox:~# docker run --name "my-http-server" -d httpd 5faa46b16ea9437f7230cb6c276014640e7cc73b661341fbe38305d3effbaebd root@jimo-VirtualBox:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5faa46b16ea9 httpd "httpd-foreground" 5 seconds ago Up 4 seconds 80/tcp my-http-server
通过history可看到是通过CMD执行的:
1 2 3
root@jimo-VirtualBox:~# docker history httpd IMAGE CREATED CREATED BY SIZE COMMENT fb2f3851a971 3 weeks ago /bin/sh -c #(nop) CMD ["httpd-foreground"] 0B