Operation of the mkdir command with dockerfile

The reason is that you are mounting a volume from your host to /var/www/html.
Step by step:

  1. RUN mkdir -p /var/www/html/foo creates the foo directory inside the filesystem of your container.
  2. docker-compose.yml ./code:/var/www/html “hides” the content of /var/www/html in the container filesystem behind the contents of ./code on the host filesystem.

So actually, when you exec into your container you see the contents of the ./code directory on the host when you look at /var/www/html.

Fix: Either you remove the volume from your docker-compose.yml or you create the foo-directory on the host before starting the container.

Additional Remark: In your Dockerfile you declare a volume as VOLUME ./code:/var/www/html. This does not work and you should probably remove it. In a Dockerfile you cannot specify a path on your host.

Quoting from docker:

The host directory is declared at container run-time: The host directory (the mountpoint) is, by its nature, host-dependent. This is to preserve image portability. since a given host directory can’t be guaranteed to be available on all hosts. For this reason, you can’t mount a host directory from within the Dockerfile. The VOLUME instruction does not support specifying a host-dir parameter. You must specify the mountpoint when you create or run the container.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)