07docker 安装Nginx

07docker 安装Nginx

1、搜索nginx

需要版本确定的通过docker hub上搜索nginx 查看对应的版本(推荐去docker hub上搜索,可以查看帮助信息)

[root@MyCould home]# docker search nginx
NAME                                          DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                                         Official build of Nginx.                        16863     [OK]       
linuxserver/nginx                             An Nginx container, brought to you by LinuxS…   168                  
bitnami/nginx                                 Bitnami nginx Docker Image                      131                  [OK]

2、下载nginx

[root@MyCould home]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete 
a9edb18cadd1: Pull complete 
589b7251471a: Pull complete 
186b1aaa4aa6: Pull complete 
b4df32aa5a72: Pull complete 
a0bcbecc962e: Pull complete 
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@MyCould home]# 

3、运行并测试nginx

[root@MyCould home]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
nginx        latest    605c77e624dd   4 months ago   141MB
centos       latest    5d0da3dc9764   8 months ago   231MB

# -d  后台运行
# --name  容器命名
# -p  容器端口映射: 宿主机端口:容器端口

[root@MyCould home]# docker run -d --name nginx01 -p 3344:80 nginx 
a6151fc980ad8b1fe2c5a320c6200c27f56ed1b6620d701fd10c9254f1ee3f1f
[root@MyCould home]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES
a6151fc980ad   nginx     "/docker-entrypoint.…"   4 seconds ago   Up 3 seconds   0.0.0.0:3344->80/tcp, :::3344->80/tcp   nginx01
[root@MyCould home]# 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@MyCould ~]# docker exec -it nginx01 /bin/bash
root@a6151fc980ad:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@a6151fc980ad:/# cd /etc/nginx/
root@a6151fc980ad:/etc/nginx# ls
conf.d	fastcgi_params	mime.types  modules  nginx.conf  scgi_params  uwsgi_params

端口映射【暴露,转发】的概念:

.

阿里云开放端口配置

思考问题: 我们每次改动nginx配置文件,都需要进入容器内部? 十分的麻烦,我要是可以在容器外部提供一个映射路径,达到在容器修改文件名,容器内部就可以自动修改? -v 数据卷

posted @ 2022-06-10 19:13  Redskaber  阅读(74)  评论(0)    收藏  举报