Search code examples
dockerdocker-composedockerfilecontainersdocker-volume

Mount folder to docker container via dockerfile or docker-compose.yml file?


I need to edit nginx.conf file in /etc/nginx/ folder from a service from within a docker container. Is there a way to do this through Dockerfile or docker-compose.yml file? All the solutions I have come across only mention using docker run command.


Solution

  • Well there are multiple ways, I assume you want your docker container to have specific files while running right? then I would recommend use in Dockerfile like this

         COPY  nginx.conf /etc/nginx/
    

    I would highly suggest copy command because this copy of file will live along with image.

    or you can mount this via docker-compose like this

    services:
      frontend:
        build: ./nginx
        volumes:
          - ./nginx.conf:/etc/nginx/
        container_name: nginx