运行一个容器,未挂载本地目录 # docker run -d --name web1 nginx:latest
# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c4ad9f2c15fa nginx:latest "/docker-entrypoint.…"46 seconds ago Up 44 seconds 80/tcp web1
使用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>
查看容器中/usr/share/nginx/html目录中目录或子目录 # docker exec web ls /usr/share/nginx/html 50x.html index.html
运行web4容器,使用--mount选项,实现数据卷挂载 # docker run -d --name web4 --mount src=nginx-vol,dst=/usr/share/nginx/html nginx:latest
或
运行web4容器,使用-v选项,实现数据卷挂载 # docker run -d --name web4 -v nginx-vol:/usr/share/nginx/html/ nginx:latest
查看容器运行后数据卷中文件或子目录 # ls /var/lib/docker/volumes/nginx-vol/_data/ 50x.html index.html
使用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>