Docker | Docker基本操作命令
Docker | Docker基本操作指令
总结
有关Docker的基本操作命令。
什么可以被视为基本操作命令,是相对而言的。
指令
跑步
- Basic Format
$ docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
- Ubuntu 1404 のイメージを指定して、コンテナを起動し、 perl の Hello world を呼び出す
$ sudo docker run ubuntu:14.04 /usr/bin/perl -e 'print "Hello world\n"'
Hello world
- Ubuntu 1404 のイメージを指定して、コンテナを対話モードで起動する。
$ sudo docker run -i -t ubuntu:14.04
root@c7a3fa22c343:/# echo hoge
hoge
root@c7a3fa22c343:/# perl -e 'print "hoge\n"'
hoge
root@c7a3fa22c343:/# exit
- tomcat:8.0 のイメージを指定して、ポート指定+デーモン起動する。
$ sudo docker run -d -p 8888:8080 tomcat:8.0
$ curl http://localhost:8888 | grep Congratulations
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 <h2>If you're seeing this, you've successfully installed Tomcat. Congratulations!</h2>
100 11230 0 11230 0 0 676k 0 --:--:-- --:--:-- --:--:-- 685k
请把以下内容用中文进行同义转述,只需要一种表达方式:
ps
查看容器列表
- 起動中のコンテナの一覧を確認する
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0d8e6ab4aafb tomcat:8.0 "catalina.sh run" 6 minutes ago Up 6 minutes 0.0.0.0:8888->8080/tcp prickly_kowalevski
$ sudo docker stop prickly_kowalevski
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- すべてのコンテナの一覧を確認する
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
111e16dc2e22 ubuntu:14.04 "\"/usr/bin/perl -e 2 minutes ago Exited (0) 3 seconds ago sick_poincare
$ sudo docker stop sick_poincare
sick_poincare
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
111e16dc2e22 ubuntu:14.04 "\"/usr/bin/perl -e 2 minutes ago Exited (0) 12 seconds ago sick_poincare
记录
输出容器的日志
# tomcat8 のコンテナを起動
$ sudo docker run -d -p 8888:8080 tomcat:8.0
# コンテナ一覧を確認
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c0d27e685d09 tomcat:8.0 "catalina.sh run" 4 minutes ago Up 4 minutes 0.0.0.0:8888->8080/tcp romantic_goodall
# コンテナの NAME を指定してログを確認
$ sudo docker logs romantic_goodall
# 略
25-Nov-2014 06:51:07.182 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1663 ms
停止
停止正在运行的容器。
- Name を指定して 1 コンテナ停止
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c0d27e685d09 tomcat:8.0 "catalina.sh run" 4 minutes ago Up 4 minutes 0.0.0.0:8888->8080/tcp romantic_goodall
$ sudo docker stop romantic_goodall
romantic_goodall
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 全コンテナ停止
$ sudo docker run -d -p 8888:8080 tomcat:8.0
$ sudo docker run -d -p 8889:8080 tomcat:8.0
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ebd368bc17d9 tomcat:8.0 "catalina.sh run" 7 seconds ago Up 6 seconds 0.0.0.0:8889->8080/tcp furious_turing
68108e43c1f1 tomcat:8.0 "catalina.sh run" About a minute ago Exited (143) 33 seconds ago backstabbing_feynman
$ sudo docker stop `sudo docker ps -a -q`
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ebd368bc17d9 tomcat:8.0 "catalina.sh run" About a minute ago Exited (143) 1 seconds ago furious_turing
68108e43c1f1 tomcat:8.0 "catalina.sh run" 2 minutes ago Exited (143) About a minute ago backstabbing_feynman
删除
- Name を指定して 1 コンテナ削除
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fc588913e43e tomcat:8.0 "catalina.sh run" 2 minutes ago Exited (143) 2 seconds ago prickly_darwin
$ sudo docker rm prickly_darwin
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 全コンテナ削除(起動中のコンテナがある場合はエラー)
$ sudo docker run -d -p 8888:8080 tomcat:8.0
$ sudo docker run -d -p 8889:8080 tomcat:8.0
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ebd368bc17d9 tomcat:8.0 "catalina.sh run" 7 seconds ago Up 6 seconds 0.0.0.0:8889->8080/tcp furious_turing
68108e43c1f1 tomcat:8.0 "catalina.sh run" About a minute ago Exited (143) 33 seconds ago backstabbing_feynman
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ebd368bc17d9 tomcat:8.0 "catalina.sh run" About a minute ago Exited (143) 1 seconds ago furious_turing
68108e43c1f1 tomcat:8.0 "catalina.sh run" 2 minutes ago Exited (143) About a minute ago backstabbing_feynman
$ sudo docker rm `sudo docker ps -a -q`
ebd368bc17d9
68108e43c1f1
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES