拉取镜像
docker pull nginx
启动Nginx
docker run -d --name nginx01 -p 3344:80 nginx
参数意义:
- -d:后台运行
- —name:给容器取命名
- -p:指定端口暴露映射,Nginx默认80端口,和服务器的外网3344映射,外网访问服务器的3344端口,就能访问到这个Nginx容器的80端口了
进入容器
可以看到里面存在Nginx的配置文件,可以自己改[root@izj6cev682kqg86i4ogj8rz ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7b66cca418c6 nginx "/docker-entrypoint.…" 6 minutes ago Up 6 minutes 0.0.0.0:3344->80/tcp nginx01
08e8a0cbc58e centos "/bin/bash" 4 hours ago Up 4 hours gracious_chaum
[root@izj6cev682kqg86i4ogj8rz ~]# docker exec -it nginx01 /bin/bash
root@7b66cca418c6:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@7b66cca418c6:/# cd /etc/nginx
root@7b66cca418c6:/etc/nginx# ls
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
root@7b66cca418c6:/etc/nginx#
停止Nginx
Nginx被停止了以后,外网访问3344端口就访问不到了[root@izj6cev682kqg86i4ogj8rz ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7b66cca418c6 nginx "/docker-entrypoint.…" 11 minutes ago Up 10 minutes 0.0.0.0:3344->80/tcp nginx01
08e8a0cbc58e centos "/bin/bash" 4 hours ago Up 4 hours gracious_chaum
[root@izj6cev682kqg86i4ogj8rz ~]# docker stop 7b66cca418c6
7b66cca418c6
[root@izj6cev682kqg86i4ogj8rz ~]#