繁体   English   中英

Docker. docker-compose up后在container中创建目录并赋予r/w权限

[英]Docker. Create directory in container after docker-compose up and give it r/w permissions

例如,如何在同一个容器中创建另一个/tmp目录并赋予它r/w权限?

docker-compose.yml:

nginx:
    image: nginx
    ports:
      - 80:80
    volumes:
      - ./volumes/nginx/conf.d:/etc/nginx/conf.d
    command: nginx -g "daemon off;"
    networks:
      - network

如果仅使用docker-compose而不使用Dockerfile,则可以通过以下方式完成:

您可以像这样进入容器:

docker exec -ti $(docker ps --filter name='nginx' --format "{{ .ID }}")

然后,在容器内,您可以运行:

mkdir /tmp2
chmod 755 /tmp2

您可以通过在Dockerfile定义目录来创建目录或执行任何其他操作。 在与docker-compose.yml相同的目录中创建一个Dockerfile:

touch Dockerfile

添加到您的Dockerfile的以下行:

RUN mkdir /tmp2
RUN chmod 755 /tmp2

在docker-compose.yaml中添加构建信息:

nginx:
      image: nginx
      build: .
      ports:
        - 80:80
      volumes:
        - ./volumes/nginx/conf.d:/etc/nginx/conf.d
      command: nginx -g "daemon off;"
      networks:
        - network

只需添加一个包含您要创建的目录的卷,它就会在启动期间自动创建

nginx:
    image: nginx
    ports:
      - 80:80
    volumes:
      - ./volumes/nginx/conf.d:/etc/nginx/conf.d
      - ./volumes/hosted-direcotry/hosted-sub-direcotry:/etc/created-direcotry/created-sub-directory/
    command: nginx -g "daemon off;"
    networks:
      - network

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM