user964941
user964941

Reputation: 11

Building my own Docker image from officiall Wordpress image

I’m trying to build my own image based on image from Docker Hub What I want to do is to add some new files to existing file system on image I created Dockerfile with the following content:

from wordpress

copy . /var/www/html/wp-content/plugins

Here I’m trying to fetch official wordpress image and then copy some files in my current directory to plugins folder. Then I built the image and got new image lets call it newimage. Then I’m trying to run container based on this newimage and also I want to use volume for this contatiner to store data on my host machine. I’m doing this command:

docker run -d --name wp -v wp-volume:/var/www/html newimage

The container starts well but when I’m trying to check the folder var/www/html/wp-content/plugins I can’t see the files that was copied on stage of building this image. But if I do the command: docker run -d --name wp newimage without using a volume I can see the files that was copied in the path /var/www/html/wp-content/plugins so why if i run container WITH volume I can’t see my files but If I run container WITHOUT volume I can see my files in /var/www/html/wp-content/plugins

Upvotes: 0

Views: 316

Answers (1)

Hans Kilian
Hans Kilian

Reputation: 25120

When you mount a volume to a directory in the container, all the contents in that directory is replaced with the volume contents.

In your case, you mount your volume on /var/www/html. That means that all existing content in your image under that path, i.e. your plugin, becomes hidden and inaccessible.

Unfortunately you can't 'merge' the existing image content with the content of the volume. A good habit to get into is to always mount volumes on empty directories in the image so you don't accidentally hide content.

Upvotes: 1

Related Questions