# docker run -d nginx:latest 9834c8c18a7c7c89ab0ea4119d11bafe9c18313c8006bc02ce57ff54d9a1cc0c
命令解释 docker run 启动一个容器 -d 把容器镜像中需要执行的命令以daemon(守护进程)的方式运行 nginx 应用容器镜像的名称,通常表示该镜像为某一个软件 latest 表示上述容器镜像的版本,表示最新版本,用户可自定义其标识,例如v1或v2等
# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9834c8c18a7c nginx:latest "/docker-entrypoint.…"24 seconds ago Up 23 seconds 80/tcp condescending_pare
# ip a s ...... docker0网桥,用于为容器提供桥接,转发到主机之外的网络 5: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:42:d5:c3:d4:cc brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 valid_lft forever preferred_lft forever inet6 fe80::42:d5ff:fec3:d4cc/64 scope link valid_lft forever preferred_lft forever 与容器中的虚拟网络设备在同一个命名空间中,用于把容器中的网络连接到主机 9: veth393dece@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default link/ether 02:e3:11:58:54:0f brd ff:ff:ff:ff:ff:ff link-netnsid0 inet6 fe80::e3:11ff:fe58:540f/64 scope link valid_lft forever preferred_lft forever
1.2.3 使用curl命令访问
# curl http://172.17.0.2
返回结果,表示访问成功! <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } 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 forusing nginx.</em></p> </body> </html>
二、Docker命令
2.1 Docker命令获取帮助方法
# docker -h Flag shorthand -h has been deprecated, please use --help
Usage: docker [OPTIONS] COMMAND 用法
A self-sufficient runtime for containers 功能介绍
Options: 选项 --config string Location of client config files (default "/root/.docker") -c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use") -D, --debug Enable debug mode -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") --tlskey string Path to TLS key file (default "/root/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit
Commands: 未分组命令 attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile 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 events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images 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 tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE 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 version Show the Docker version information wait Block until one or more containers stop, then print their exit codes
查看网络信息 [root@948f234e22a1 /]# ip a s 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 12: eth0@if13: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid0 inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0 valid_lft forever preferred_lft forever
查看进程 [root@948f234e22a1 /]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 10.00.1120362172 pts/0 Ss 09:580:00 bash root 160.00.0446521784 pts/0R+ 10:020:00ps aux
# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9f2eea16da4c centos:latest "bash"2 days ago Up 3 seconds c2
# docker stop c2 或 # docker stop 9f2eea16da4c
# docker rm c2 或 # docker rm 9f2eea16da4c
2.3.9.2 批量删除容器
# docker ps --all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 948f234e22a1 centos:latest "bash"2 days ago Exited (0) 2 days ago c1 01cb3e01273c centos:latest "bash"2 days ago Exited (0) 2 days ago systemimage1 46d950fdfb33 nginx:latest "/docker-ent..."2 days ago Exited (0) 2 days ago upbeat_goldberg