03:创建容器常用选项

创建容器常用选项:

废话不多说,直接看帮助命令:

[root@localhost ~]# 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 and the 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 or more 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 one or 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.
[root@localhost ~]#

常用的做个截图解释:

来个实例:

# 创建一个后台运行nginxweb的容器,主机名为nginxweb,容器名为nginx_web,主机端口8080映射到容器的80端口,设置环境变量test为123456
[root@localhost ~]# docker container run -itd --name nginx_web -e test=123456 -p 8080:80 -h nginxweb nginx d90c0947c0074f22a3226cc615a4584c6453c75813629b4285a77f5be353767a [root@localhost ~]# 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 [root@localhost ~]# docker logs nginx_web [root@localhost ~]# 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> [root@localhost ~]# 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" "-" [root@localhost ~]# 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 [root@localhost ~]# docker exec -it nginx_web bash root@nginxweb:/# hostname nginxweb root@nginxweb:/# echo $test 123456 root@nginxweb:/# exit exit [root@localhost ~]# docker container stop nginx_web nginx_web [root@localhost ~]# 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 [root@localhost ~]# docker container rm d90c0947c007 d90c0947c007 [root@localhost ~]# docker container ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@localhost ~]#

猜你喜欢

转载自www.cnblogs.com/zheng-weimin/p/10264283.html