Skip to content
Advertisement

Docker image pushing but my volume not persist

This message to clear up a problem I am having with the use of docker with my php application.

Indeed, I execute locally my dockers images (nginx, phpmyadmin and php with my application) and everything works fine. However, I use a volume mounted in my container app with php which allows me to be able to modify hot files (without need to build at each edit).

However when I push this image to a repository and I pull it on another desktop, the volume containing my application is not there.

Have you ever faced this concern?

Please find my docker-compose.yml and Dockerfile :

docker-compose.yml

JavaScript

Dockerfile

JavaScript

Thanks in advance

Advertisement

Answer

This is expected behavior, because the data inside Volumes are not part of an image. Volumes are used to persist data generated in containers or to pass dynamic data into containers via bind-mounts e.g. configs, credentials or certificates.

https://docs.docker.com/storage/volumes/

Your docker-compose.yml and its services using volumes mounting your local directory via - .:/path/to/dir are only good for local development, because you may see changes of your application instant and without having to rebuild images.

If you want to see your code inside the images on another machine you need to use COPY in your Dockerfile, rebuild the image and push every time you change your code !

You will also need to change your docker-compose.yml by adding volumes.

https://docs.docker.com/compose/compose-file/#volumes

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement