[root@sail ~]# docker run -d centos 0aee6f74b913f120195ca323892867bba7d72f2671f2f8b17278a3e029ad5bfd [root@sail ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
使用 docker run -d 启动,也并不能保证容器一定能在后台运行,如果没有前台使用,容器启动后发现自己没有提供服务,会立刻停止。
[root@sail ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c3d59f55d600 centos "/bin/sh -c 'while t…"24 minutes ago Up 5 seconds musing_poincare
[root@sail ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 96ed3fe3e7f1 centos "/bin/bash"15 hours ago Up 15 hours centos01
[root@sail ~]# docker exec -it 96ed3fe3e7f1 /bin/bash [root@96ed3fe3e7f1 /]# ls bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[root@sailhome]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest f652ca386ed1 7 days ago 141MB
运行镜像
1 2 3 4 5
[root@sailhome]# docker run -d --name=nginx01 -p 3344:80 nginx f58fb3ed8c5587d2c28567c865759438e449f2fd65889f2910286b9cd74debec [root@sailhome]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f58fb3ed8c55 nginx "/docker-entrypoint.…"23 seconds ago Up 22 seconds 0.0.0.0:3344->80/tcp nginx01
[root@sailhome]# curl localhost:3344 <!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>
外网访问测试
如果是使用阿里云服务器,需要先开启端口。
使用阿里云的公网 IP 即可进行访问。
出现此页面,即代表 Nginx 部署成功。
查看启动的容器
1 2 3
[root@sailhome]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f58fb3ed8c55 nginx "/docker-entrypoint.…"12 minutes ago Up 12 minutes 0.0.0.0:3344->80/tcp nginx01
[root@sailbin]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fe247e0ef80d tomcat "catalina.sh run" About a minute ago Up About a minute 0.0.0.0:8080->8080/tcp tomcat01
这里选择直接启动的方式,若本地没有该镜像,则先从官方库拉取。
进入容器
1 2 3 4 5 6 7
[root@sailsail]# docker exec -it tomcat01 /bin/bash root@fe247e0ef80d:/usr/local/tomcat# ls BUILDING.txt CONTRIBUTING.md LICENSE NOTICE README.md RELEASE-NOTES RUNNING.txt bin conf lib logs native-jni-lib temp webapps webapps.dist work
root@fe247e0ef80d:/usr/local/tomcat# cd webapps root@fe247e0ef80d:/usr/local/tomcat/webapps# ls root@fe247e0ef80d:/usr/local/tomcat/webapps#