docker部署Nginx

 

(核心:端口暴露)

 

1,搜索Nginx镜像

docker search nginx

 

2,下载镜像

docker pull nginx

 

3,运行容器,起名为nginx01 ,通过本机的3344端口号可以访问到容器的80端口你

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

 

端口暴露的概念:

 

 

 

 

4,先本机测试以下

 

[root@CentOs /]# 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 for using nginx.</em></p>
</body>
</html>
[root@CentOs /]#

 

或者:

 

 

 

 

5,进入nginx

 

[root@CentOs /]# docker exec -it nginx01 /bin/bash
root@b6e940ca5783:/#

进入后可以找一下nginx的配置文件

root@b6e940ca5783:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@b6e940ca5783:/# cd /etc/nginx/
root@b6e940ca5783:/etc/nginx# ls
conf.d    fastcgi_params    mime.types  modules  nginx.conf  scgi_params  uwsgi_params
root@b6e940ca5783:/etc/nginx#

 

思考:

我们每次改动nginx配置文件,都要进入容器内部,十分的麻烦,要是可以在容器外部提供一个映射路径,

达到在容器修改文件名,容器内部也就可以自动修改了? -v数据卷

 

posted @ 2022-03-19 10:30  屯子里唯一的架构师  阅读(801)  评论(0编辑  收藏  举报