I recognized a very strange behavior of my docker-compose:
Here come a minimal (not) working example:
This is my docker-compose.yml:
and my PHP.Dockerfile
RUN apt-get update
When I try do do “docker-compose up” this results in
WARNING: Some networks were defined but are not used by any service: reverse-proxy
Step 1/2 : FROM php:7.4-fpm
Step 2/2 : RUN apt-get update
ERROR: Service 'moodle_test-app' failed to build: cannot mount volume over existing file, file exists /var/lib/docker/overlay2/b452c2217898ab397e68c5741ea6bfc8011afcc5d1a5f786aa17bfa7b4437d51/merged/usr/local/etc/php/php.ini
The first warning is clear to me. But where comes the error from? Even when I comment out the whole “volumes” part of the docker-compose file I get the same error.
But, when I remove the line
RUN apt-get update
from the dockerfile, the container starts as expect.
-docker version: Docker version 20.10.17, build 100c701
-docker-compose version 1.25.5, build 8a1c60f6
Any idea what is going wrong here?
Thank you very much in advance!
What happens when you just run
docker-compose build without up?
Compose 1.25 is an older version so it can also be a bug. I think you could get that “over existing file” message if you define a volume in the Dockerfile but the destination path is not a folder but an existing file or an existing file is the part of that path. Since you clearly don’t have any volume definition in the Dockerfile, but you have it in the compose file, the error message may come from there even though it tells you the build failed and not the container. If it is the case, check your source paths, especially
./conf/local.ini. If the source file does not exist, it docker compose will create it as a folder so you can’t mount it, because
php.ini is a file, not a folder.
On the other hand you wrote:
So I would try to run
and then “up” again to make sure you really try to mount the current volumes. Sometimes, when you only run “up”, compose keeps the older volumes and shows you a notice. So the best if you check your source paths and also run
docker-compose down and up again if everything seems right.
Hey, thank you for your answer!
I’ve already checked all the paths in the “volumes” part. So, this is definitely fine.
Moreover, when I remove the “build” part in the docker-compose file but add the PHP image directly i.e.
# context: PHP/
# dockerfile: PHP.Dockerfile
The container is build and starts without an error.
I’ve already tested
without success. I’ve also tried some additional options as “–no-cache”, “–force-recreate”, “–build” Without success. Also tried the “–verbose” option, but did not found any hint to get clear of this strange behavior.
Then my only idea is to try a newer Docker Compose version. At least the latest v1. Before updating compose, you can try to build with
docker build instead of docker compose. If it works, you can update docker compose. If it doesn’t work, then the latest compose will not help.
I upgrade docker-compose to 2.6.0 which is the latest version from official ubuntu packages.
Now, everything is running like a charm :).
Thank you again!