0

I'm a newbie to Docker, I have an application for which I am exploring Docker. With docker compose i can up multiple containers, till here everything is working as expected. We have respective .sh and .yml files.

Scenario which I'm having problem to understand is there is one container where I can place my custom directory, files and it's mentioned that at the time of container start/restart custom files will be copied to the webroot of that container. I would like to understand what happened behind the scene.

  • Will it create a new image and deploying that image at the time of container start/restart.
  • It will just move those files in the new container as it is.

Any help to understand above scenario is much appreciated. Thanks in advance.

NGupta
  • 77
  • 8

1 Answers1

1

Depends on how you build and run the container. If you have a Dockerfile and in there you specify COPY or ADD /my/files/ /to/container/path this will result in copying /my/files inside the container and it will create a new image layer (each command you run inside the Dockerfile creates a new layer)

This means that it would take a snapshot of your files at that point in time and copy it over to the Docker image.

However, if you just use your docker-compose file and mount those files, the files will be shared between your host and the container. Which means you could edit files on your localhost and immediately sync'ed with the container or vice versa.

Sergiu
  • 2,928
  • 3
  • 27
  • 37
  • Thanks for the help @Sergju, I have checked Docker file and can't find **COPY** or **ADD**, In the docker-compose file, I can see Volumes but still editing or addition of file requires the restart of container. Any way to avoid restart and get it synced. Also please confirm that, this volume or mount will also create a new image layer. – NGupta Nov 07 '17 at 07:15
  • @NGupta No prob, if you have specified a *volume* in your docker-compose file that **wouldn't** create an additional image layer. Image layers are created when you build a Docker image. Having to restart the container shouldn't happen if you mount a volume, only if you change the paths of the volumes. Would you mind pasting your docker-compose file please? – Sergiu Nov 07 '17 at 07:22
  • Thanks for the quick response. I'm afraid to say that I cant paste the docker-compose file here. >> if you have specified a volume in your docker-compose file that wouldn't create an additional image layer. In this case how the changes will be synced, I would like to understand that. As our provider had mentioned in document that these changes will be available once container will be restarted. – NGupta Nov 07 '17 at 07:40
  • @NGupta well not here, in your original question I meant. I am not sure what *your provider* meant by that, so that's why I want to have a look at your docker compose file to see what's going on – Sergiu Nov 07 '17 at 07:59
  • Thanks @Sergiu. As the config file contains credentials as well, thats why i can't share it. I'm sharing here Volume section for specified container, if you can help me to understand with that. volumes: -"/usr/local/application/app/custom_dir1:/var/www/application_root/app/custom-dir1" – NGupta Nov 07 '17 at 09:03
  • @NGupta No I don't see why you would have to restart the container, if you go to your /var/www/application_root/app/customer-dir1 can you see your files there? You can also add a test file in **/usr/local/application/app/custom_dir1** and then exec into the container and see if the file exists. – Sergiu Nov 07 '17 at 09:09