Files created during docker build not present in container created from image

I have the following Dockerfile

FROM wordpress

#make sure necessary tools for publishing are installed
RUN curl -sL https://deb.nodesource.com/setup_4.x | bash - && \
	apt-get install -y nodejs git && \
	npm install -g npm gulp bower

ADD . /var/www/html/wp-content/themes/new-theme

RUN cd /var/www/html/wp-content/themes/new-theme \
	&& npm install \
	&& npm run build \
	&& rm -rf node_modules \
	&& rm -rf bower_components \
	&& find ./* -type f -printf "%h%f\n" | sort \
	&& cd /

VOLUME ["/var/www/html/wp-content/themes/new-theme"]

ENTRYPOINT ["/entrypoint.sh"]
CMD ["apache2-foreground"]

When I build it, the second RUN command produces several files that get dropped into the /var/www/html/wp-content/themes/ca-ticket.com/dist folder, and when I view the build log I can see clearly that the files are getting created (that is why the find ./* -type f -printf "%h%f\n" | sort is there.

From the log:

build	11-Apr-2016 18:51:01	./dist/scriptsjquery.js
build	11-Apr-2016 18:51:01	./dist/scriptsjquery.js.map
build	11-Apr-2016 18:51:01	./dist/scriptsmain.js
build	11-Apr-2016 18:51:01	./dist/scriptsmain.js.map
build	11-Apr-2016 18:51:01	./dist/stylesmain.css
build	11-Apr-2016 18:51:01	./dist/stylesmain.css.map

… and so on.

However, when I create a container from this image, the /var/www/html/wp-content/themes/ca-ticket.com/dist simply doesn’t exist!

The build command is:

docker build --force-rm=true --tag="<tag here>" /path/to/context

I’ve also tried with the --no-cache option with no change to the result.

I’m running the image with:

docker run --name <name> -d -p 81:80 -e WORDPRESS_DB_HOST=<dbhost> -e WORDPRESS_DB_USER=<dbuser> -e WORDPRESS_DB_PASSWORD=<pass> -e WORDPRESS_DB_NAME=<dbname> -e WORDPRESS_TABLE_PREFIX=<tblprefix> <imagename>

I’m suspect I must be doing something silly to cause docker to ignore a layer, but I’m not sure what is wrong about this process.

You have VOLUME ["/var/www/html/wp-content/themes/new-theme"]. That means a volume will be mounted in that location when you run the image. Volumes are just bind mounts. When something is mounted to a directory, it hides any contents of that directory.

You may want to put that VOLUME somewhere else.

But the files that get added in the ADD stage are all present at the same path when I do a docker exec -t -i <containername> bash and ls /var/www/html/wp-content/themes/new-theme - the only missing files are those that get generated during the subsequent RUN.

I just tried re-running with the volume commented out with the exact same outcome. I have the volume there because when I am doing dev work I mount the volume to a local path for me to work on the theme, but when publishing the image I run without the volume at all.

If you have VOLUME in the dockerfile, that location will always be a volume.

What are the exact commands you are using for the docker build and docker run ?

The build command is:

docker build --force-rm=true --tag="<tag here>" /path/to/context

I’ve also tried with the --no-cache option with no change to the result.

I’m running the image with:

docker run --name <name> -d -p 81:80 -e WORDPRESS_DB_HOST=<dbhost> -e WORDPRESS_DB_USER=<dbuser> -e WORDPRESS_DB_PASSWORD=<pass> -e WORDPRESS_DB_NAME=<dbname> -e WORDPRESS_TABLE_PREFIX=<tblprefix> <imagename>

I’m currently trying to do a full rebuild (--no-cache) with the volume removed.

Do a docker inpsect on the running container that has a problem-- does it list a volume in that location?

Just completed a build with the volume commented out, and docker inspect shows:

"Volumes": { "/var/www/html": {} },

That volume comes from the base wordpress image, and as you can see the volume I was adding is no longer present.

The contents of the npm run build output are still not present.

I’m hesitant to post it because it it quite large, but I can post the entire output of the docker build itself if you think that’d be helpful.

Is it possible I’m experiencing an issue similar to https://github.com/docker/docker/issues/3639 ?

There is a volume created in the base image, which I am copying files to, and those files do not seem to be present.

Ah yes,

The wordpress container will do a bunch of black magic with /var/www/html. Due to wordpress’s approach in keeping state on the filesystem, the wordpress’s entrypoint.sh script will populate it with a vanilla wordpress install at runtime.

Any changes to that location at build time are masked by the /var/www/html volume.

What you might have to do is ADD your files to another location, and then get the wordpress entrypoint.sh script to set up a symlink at runtime after doing the initial wordpress download/install.

The wordpress image’s entrypoint script can be found here: https://github.com/docker-library/wordpress/blob/master/docker-entrypoint.sh

I’ve currently just folded their Dockerfile into my own and removed the extra VOLUME - if this works I may have to just fork their dockerfile and do exactly what you suggested.

Thank you so much for the help; can be tough working in a vacuum!

Oh - crap. Now I see what you mean with the black magic / keeping state. It needs the volume to function. Symlinks it is!