【问题标题】:How to mount a folder into nginx public folder如何将文件夹挂载到 nginx 公用文件夹中
【发布时间】:2020-12-27 11:06:28
【问题描述】:

我在主机中有一个目录,我想将它挂载到一个容器和 Nginx 公用文件夹,它本身就是一个容器。

这是我的 docker-compose.yml 文件:

version: "3.3"
services:
    nodeserver:
        build:
            context: ./app
        volumes:
            - /client-images:/usr/src/app/client-images
        ports:
            - "9000:9000"
    nginx:
    restart: always
        build:
            context: ./nginx
        ports:
            - "80:6000"
    db:
        image: mariadb
        restart: always
        environment:
            MYSQL_ROOT_PASSWORD: my_secret_mysql_password
    phpmyadmin:
        image: phpmyadmin
        restart: always
        ports:
            - "8080:80"
        environment:
            - PMA_ARBITRARY=1
volumes:
  images:

我的图像位于 /client-images 目录中,但如何将它们挂载到 Nginx 公共目录并访问它们?

【问题讨论】:

    标签: linux docker nginx docker-compose


    【解决方案1】:
        nginx:
            restart: always
                build:
                    context: ./nginx
                ports:
                    - "80:6000"
                volumes:
                    - '/client-images:/usr/share/nginx/html'
    

    【讨论】:

      【解决方案2】:

      您应该绑定到/usr/share/nginx/html 您的文件。这是默认位置。如果你想改变默认位置,你应该改变/etc/nginx/conf.d/default

      我更喜欢通过 nginx:1.19-alpine 使用模板。

      templates docs

      【讨论】:

        【解决方案3】:
            nginx:
                restart: always
                    build:
                        context: ./nginx
                    ports:
                        - "80:6000"
                    volumes:
                        - '/client-images:/usr/share/nginx/html'
        

        【讨论】:

        • 请添加一些有用的解释。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-07-11
        • 1970-01-01
        • 2019-04-10
        • 1970-01-01
        • 2014-04-30
        • 1970-01-01
        • 2021-12-14
        相关资源
        最近更新 更多