# 搜索nginx
[root@VM-0-5-centos ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 14228 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1932 [OK]
# 下载镜像
[root@VM-0-5-centos ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
6ec7b7d162b2: Already exists
cb420a90068e: Pull complete
2766c0bf2b07: Pull complete
e05167b6a99d: Pull complete
70ac9d795e79: Pull complete
Digest: sha256:4cf620a5c81390ee209398ecc18e5fb9dd0f5155cd82adcbae532fec94006fb9
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
# 查看安装的镜像
[root@VM-0-5-centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest ae2feff98a0c 13 days ago 133MB
centos latest 300e315adb2f 3 weeks ago 209MB
# 启动nignx
# --name 重命名容器
# -p 外部端口:容器端口 容器名 # 6000是外部访问端口,80是nginx端口,nginx是容器名。完整IP是 http://172.0.0.1:6000/ (172.0.0.1是服务器的IP)
[root@VM-0-5-centos ~]# docker run -d --name nginx01 -p 6000:80 nginx
2456e22d581cb8aed65cbf9b2e3d6c3f6f5ee862bac2faa65f081faf29f41a98
# 查看到nginx已经开启
[root@VM-0-5-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2456e22d581c nginx "/docker-entrypoint.…" 5 seconds ago Up 5 seconds 0.0.0.0:6000->80/tcp nginx01
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
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 for using nginx.</em></p>
</body>
</html>
# 启动nginx
[root@VM-0-5-centos ~]# curl localhost:6000
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
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 for using nginx.</em></p>
</body>
</html>
# 重新进入nignx,新开一个终端
[root@VM-0-5-centos ~]# docker exec -it nginx01 /bin/bash
root@2456e22d581c:/# ls
bin boot dev docker-entrypoint.d docker-entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
# 查看容器内nginx安装路径
root@2456e22d581c:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
# 查看nginx配置路径
root@2456e22d581c:/# cd /etc/nginx/
root@2456e22d581c:/etc/nginx# ls
conf.d fastcgi_params koi-utf koi-win mime.types modules nginx.conf scgi_params uwsgi_params win-utf
# 退出容器
root@2456e22d581c:/etc/nginx# exit
exit
[root@VM-0-5-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2456e22d581c nginx "/docker-entrypoint.…" 11 minutes ago Up 11 minutes 0.0.0.0:6000->80/tcp nginx01
# 停止容器
[root@VM-0-5-centos ~]# docker stop 2456e22d581c
2456e22d581c
[root@VM-0-5-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@VM-0-5-centos ~]#
端口暴露:
问题:如果避免频繁进入容器,能在宿主机对容器centos内的环境进行配置?