部署Nginx

搜索镜像

网页搜索镜像

建议在docker hub进行搜索,可以看到帮助文档。

打开查看镜像详细信息

命令搜索镜像

docker search nginx

下载镜像

docker pull nginx

查看下载的镜像

docker images

启动镜像

docker run -d --name=nginx01 -p 3344:80 nginx

-d #后台运行

--name #给容器起名

-p #暴露端口(宿主机端口:容器内部端口)

查看运行容器

docker ps

请求测试

curl localhost:3344

进入容器

docker exec -it nginx01 /bin/bash

进入容器,搜索nginx,查看nginx配置文件,退出容器,停止容器,再次访问测试

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STAT
370ce844910c        nginx               "/docker-entrypoint.…"   17 minutes ago      Up 1
[root@localhost ~]# docker exec -it nginx01 /bin/bash
root@370ce844910c:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@370ce844910c:/# cd /etc/nginx/
root@370ce844910c:/etc/nginx# ls
conf.d		koi-utf  mime.types  nginx.conf   uwsgi_params
fastcgi_params	koi-win  modules     scgi_params  win-utf
root@370ce844910c:/etc/nginx# exit
exit
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
370ce844910c        nginx               "/docker-entrypoint.…"   19 minutes ago      Up 19 minutes       0.0.0.0:3344->80/tcp   nginx01
[root@localhost ~]# docker stop 370ce844910c
370ce844910c
[root@localhost ~]#

停止容器后便无法访问nginx

原文地址:https://www.cnblogs.com/lwenwu/p/14007622.html