REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 74435f89ab78 7 days ago 73.9MB ubuntu 18.04 8e4ce0a6ce69 7 days ago 64.2MB nginx latest 2622e6cca7eb 2 weeks ago 132MB
~$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8438eaf75dbd nginx "/docker-entrypoint.…" 9 seconds ago Up 7 seconds 0.0.0.0:8888->80/tcp MyNginx
~$ sudo curl localhost:8888 <!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>
~$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8438eaf75dbd nginx "/docker-entrypoint.…" 14 minutes ago Up 14 minutes 0.0.0.0:8888 80/tcp MyNginx # 根据容器 NAME 进入当前正在运行的 nginx 容器( docker exec -it : 特征为进入容器后开启一个新的终端 ) ```shell ~$ sudo docker exec -it MyNginx /bin/bash # 查找 nginx 的配置文件目录 ```shell whereis nginx nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx # 进入 nginx 中用于存储 html 的文件目录 ```shell cd /usr/share/nginx/ cd html/ ls 50x.html index.html # 查看 index.html 文件中的内容 ```shell cat index.html <!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>
重写 index.html 中内容
1
echo "<h1 align="center">hey guy welcome back,coffee time</h1>" > index.html
再次查看 index.html 中的内容
1 2
cat index.html <h1 align=center>hey guy welcome back,coffee time</h1>
~$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8438eaf75dbd nginx "/docker-entrypoint.…" 38 minutes ago Up 38 minutes 0.0.0.0:8888->80/tcp MyNginx
根据id停止指定容器的运行
1 2
~$ sudo docker stop 8438eaf75dbd 8438eaf75dbd
再次查看当前正在运行的容器,验证 nginx 是否被关闭
1 2
~$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES