Docker Ignore is not woking well with docker compose and my file structure

后端 未结 3 604
走了就别回头了
走了就别回头了 2021-02-06 13:21

I\'am setting up a new dockerfile and docker-compose.yml. I\'ll below show first my file structure with rails and I want to use a new .dockerignore to ignore node_modul

3条回答
  •  深忆病人
    2021-02-06 13:31

    At build time, the directive COPY . . (inside the Dockerfile) correctly copies all files not listed in .dockerignore in $RAILS_ROOT (inside the image). No problem here (check that by running docker run --rm custom-web:1.0 ls -al).

    But here you run docker-compose to start the container, and you have defined a volume :

    volumes:
        - .:/var/www/${APP_NAME}_web
    

    That means that files from the same directory as docker-compose.yml are shared between the host and the container. That's why you find all files (even those listed in .dockerignore) in $RAILS_ROOT (workdir of custom-web:1.0 image) after starting the container via docker-compose.

    If you really need to share files between your host and the container (via a volume), I'll suggest you to mount the current directory in another location than the one specified in your Dockerfile, like :

    volumes:
        - .:/${APP_NAME}_web
    

    Otherwise, using COPY . . and a volume is redundant here.

提交回复
热议问题