Simple mkdir -p not working

Why are only some created directories showing up in the final running image. Here are my steps. It should be trivial:

Use this Dockerfile:

FROM wordpress:4.8.2-php7.0-apache
RUN mkdir -pv \
             /var/www/html/blog/wp-content/uploads/pb_backupbuddy \
             /var/www/html/blog/wp-content/uploads/backupbuddy_temp \
             /var/www/html/blog/wp-content/uploads/backupbuddy_backups \
             /var/www/html/blog/wp-content/cache \
             /var/app/current/public \
             /var/www/html/blog && chown -R www-data:www-data /var/www/html/blog 

Then build it with this command: docker build -t stockmusic-blog:latest .
I see this output (truncated):

---> Running in 4c1a7a0b7ee3
mkdir: created directory '/var/www/html/blog'
mkdir: created directory '/var/www/html/blog/wp-content'
mkdir: created directory '/var/www/html/blog/wp-content/uploads'
mkdir: created directory '/var/www/html/blog/wp-content/uploads/pb_backupbuddy'
mkdir: created directory '/var/www/html/blog/wp-content/uploads/backupbuddy_temp'
mkdir: created directory '/var/www/html/blog/wp-content/uploads/backupbuddy_backups'
mkdir: created directory '/var/www/html/blog/wp-content/cache'
mkdir: created directory '/var/app'
mkdir: created directory '/var/app/current'
mkdir: created directory '/var/app/current/public'
 ---> 51cf49fe0867
Removing intermediate container 4c1a7a0b7ee3
Successfully built 51cf49fe0867
Successfully tagged stockmusic-blog:latest

The output shows the directories are being created.

Okay, lets run the container and see the newly created directories:

└─> docker run -d stockmusic-blog:latest
dde6311c8997c01386cbbc0174e0c30d164cc5d2188b6b04377aeb1e6b156538
└─> docker exec -t -i dde6311 /bin/bash
root@dde6311c8997:/var/www/html# cd /var/app/current/public/
root@dde6311c8997:/var/app/current/public# 
root@dde6311c8997:/var/app/current/public# cd /var/www/html/blog/wp-content
bash: cd: /var/www/html/blog/wp-content: No such file or directory
root@dde6311c8997:/var/www/html# cd /var/www/html/blog            
bash: cd: /var/www/html/blog/: No such file or directory

So the directory /var/app/current/public Was created successfully, but none of the other directories are there.

Why? What is going on here? I’m really pulling my hair out on this one. Thanks!

The official Wordpress image Dockerfiles declare VOLUME /var/www/html, and subsequent changes to that directory (even in derived images) are discarded.

2 Likes

@dmaze
Thank you, this helps. I found this issue which helped me work around this ‘issue’: