03:建立容器常用選項
阿新 • • 發佈:2019-01-13
建立容器常用選項:
廢話不多說,直接看幫助命令:
[[email protected] ~]# docker container --help Usage: docker container COMMAND Manage containers Commands: attach Attach local standard input, output, and error streams to a running container commit Create a new image from a container's changes cp Copy files/folders between a container andthe local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem exec Run a command in a running container export Export a container's filesystem as a tar archive inspect Display detailed information on one ormore containers kill Kill one or more running containers logs Fetch the logs of a container ls List containers pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container prune Remove all stopped containers rename Rename a container restart Restart oneor more containers rm Remove one or more containers run Run a command in a new container start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers wait Block until one or more containers stop, then print their exit codes Run 'docker container COMMAND --help' for more information on a command. [[email protected] ~]#
常用的做個截圖解釋:
來個例項:
# 建立一個後臺執行nginxweb的容器,主機名為nginxweb,容器名為nginx_web,主機埠8080對映到容器的80埠,設定環境變數test為123456
[[email protected] ~]# docker container run -itd --name nginx_web -e test=123456 -p 8080:80 -h nginxweb nginx d90c0947c0074f22a3226cc615a4584c6453c75813629b4285a77f5be353767a [[email protected] ~]# docker container ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d90c0947c007 nginx "nginx -g 'daemon of…" 7 seconds ago Up 6 seconds 0.0.0.0:8080->80/tcp nginx_web [[email protected] ~]# docker logs nginx_web [[email protected] ~]# curl 127.0.0.1:8080 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> [[email protected] ~]# docker logs nginx_web 172.17.0.1 - - [13/Jan/2019:14:07:27 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-" [[email protected] ~]# docker exec -it nginx_web "docker exec" requires at least 2 arguments. See 'docker exec --help'. Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] Run a command in a running container [[email protected] ~]# docker exec -it nginx_web bash [email protected]:/# hostname nginxweb [email protected]:/# echo $test 123456 [email protected]:/# exit exit [[email protected] ~]# docker container stop nginx_web nginx_web [[email protected] ~]# docker container ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d90c0947c007 nginx "nginx -g 'daemon of…" About a minute ago Exited (0) 4 seconds ago nginx_web [[email protected] ~]# docker container rm d90c0947c007 d90c0947c007 [[email protected] ~]# docker container ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [[email protected] ~]#