Docker 部署 Nginx,首先需要下载nginx镜像,然后启动这个镜像,就运行了一个nginx的容器了
- #查看是否存在nginx镜像:发现没有nginx镜像
- [root@localhost zph]# docker images | grep nginx
-
- #下载nginx镜像
- [root@localhost zph]# docker pull nginx
- Using default tag: latest
- latest: Pulling from library/nginx
- a378f10b3218: Pull complete
- 5b5e4b85559a: Pull complete
- 508092f60780: Pull complete
- 59c24706ed13: Pull complete
- 1a8747e4a8f8: Pull complete
- ad85f053b4ed: Pull complete
- 3000e3c97745: Pull complete
- Digest: sha256:add4792d930c25dd2abf2ef9ea79de578097a1c175a16ab25814332fe33622de
- Status: Downloaded newer image for nginx:latest
- docker.io/library/nginx:latest
-
- #再次查看是否存在nginx镜像:发现下载成功了nginx镜像
- [root@localhost zph]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- nginx latest 593aee2afb64 22 hours ago 187MB
-
- #启动nginx容器,在后台运行,不用加/bin/bash命令,因为nignx底层会执行相关命令
- [root@localhost zph]# docker run -it -d --name mynginx 593aee2afb64
- e0773deea60048d82729038535fad45308204e181da6c7a35fb44090cc552077
-
- #查看启动的容器:发现nginx已经启动
- [root@localhost zph]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- e0773deea600 593aee2afb64 "/docker-entrypoint.…" 5 seconds ago Up 2 seconds 80/tcp mynginx
- [root@localhost zph]#
启动nginx容器成功后,这样就创建了一个web服务了,验证这个容器是否成功: 进入nginx容器访问url,验证nginx
- #进入nginx容器访问url,验证nginx
- [root@localhost zph]# docker exec -it e0773deea600 /bin/bash
-
- #curl 验证是否可以打印出nginx相关html:发现可以打印,说明nginx容器创建成功
- root@e0773deea600:/# curl 127.0.0.1
- <head>
Welcome to nginx! - html { color-scheme: light dark; }
- body { width: 35em; margin: 0 auto;
- font-family: Tahoma, Verdana, Arial, sans-serif; }
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and
- working. Further configuration is required.
-
For online documentation and support please refer to
- Commercial support is available at
-
Thank you for using nginx.