-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker-compose up creates directories on host system #2781
Comments
besides, the directories are created by the "root" user, even if |
The directories are created by docker engine, not by compose itself, so this change would need to be made in the engine. #16072 was the only related issue I could find , but it's for named volumes, not host volumes. @thaJeztah do you know if there is any talk of this? |
Yes, we marked that "feature" as deprecated in 1.9, and it's targeted for removal in 1.11; https://github.com/docker/docker/blob/master/docs/deprecated.md#auto-creating-missing-host-paths-for-bind-mounts
|
Excellent. Closing this issue since it's being fixed by engine. |
Thanks @thaJeztah ! |
Thanks everyone!
|
Nooo. This was great feature. How can one then make sure paths exist if they do not yet? You have to wrap docker-compose then into a script? |
I think this signals well a need for the hooks: #1341 |
Hi @dnephin and @thaJeztah, this was un-deprecated so the problem still exists. |
I'm not sure if there is an existing issue for the mount syntax in docker-compose. There are a lot of issues that specify "mount", but most handle issues with the volumes. |
The volumes:
- type: bind
source: ./some/path/on/host
target: /some/path/in/container |
So, how a volume should be defined in |
@speller the shorthand syntax will do that; https://docs.docker.com/compose/compose-file/#short-syntax-3 volumes:
- ./some/path/on/host:/some/path/in/container Be aware though, that:
Those were the reasons for not auto-creating the paths when using the long-hand syntax, as they've been cause for lots of confusion (and unexpected behavior). |
@thaJeztah It doesn't in my case. That's why I've found this topic on google. I have a stack deployed with the docker-compose file. I'm using the short syntax. And docker fails to start containers if their volumes' host directories do not exist. The parent directory of the volume directory exists (and have the |
@speller probably better to open a new ticket for that with details (information about the version of compose you're using, as well as engine version (output of |
@thaJeztah : I am also facing the same issue. In my Dockerfile, I am changing the permission of some folder to non-root user. |
@thaJeztah I tried the long volume syntax as you mentioned above, but is there a way to print a warning if the file or directory on the host is missing? |
When using the long syntax, it should print an error and fail; version: "3.7"
services:
web:
image: nginx:alpine
volumes:
- type: bind
source: ./some/path/on/host
target: /some/path/in/container docker-compose up
Creating network "repro-2781_default" with the default driver
Creating repro-2781_web_1 ... error
ERROR: for repro-2781_web_1 Cannot create container for service web: invalid mount config for type "bind": bind source path does not exist: /Users/sebastiaan/Projects/repro/repro-2781/some/path/on/host
ERROR: for web Cannot create container for service web: invalid mount config for type "bind": bind source path does not exist: /Users/sebastiaan/Projects/repro/repro-2781/some/path/on/host
ERROR: Encountered errors while bringing up the project. |
@thaJeztah Thanks for the example. My problem was that I tried this with an existing setup. |
You have to anyway. Without auto-creation docker will error out. With auto-creation it will create the missing directories as root, which is equally undesirable. There is simply no way to avoid having to supply the missing functionality by writing some code. |
There could be a config to configure user under which to create the directory. |
That would be great! I'm currently having the issue that docker-compose up creates the directories I need (great), but when I want to tear them down and build them back up again using Jenkins, my build fails because Jenkins can't tear down root owned volumes created by Docker. |
There could be? Optimist! |
or by default under: $USER:$USER |
Any news on this? @thaJeztah tried your suggestion but still not failing if folder missing (maybe due to the compose 3.3 version?) Thanks a lot!
|
@nicolabeghin I tried reproducing, but I'm getting the error (as expected); docker-compose up
Creating network "composetest_default" with the default driver
Creating composetest_web_1 ... error
ERROR: for composetest_web_1 Cannot create container for service web: invalid mount config for type "bind": bind source path does not exist: /Users/sebastiaan/Projects/test/composetest/some/path/on/host
ERROR: for web Cannot create container for service web: invalid mount config for type "bind": bind source path does not exist: /Users/sebastiaan/Projects/test/composetest/some/path/on/host
ERROR: Encountered errors while bringing up the project. @nicolabeghin after you ran |
@thaJeztah thanks a lot for your followup! below the whole thing. I confirm there's no I must outline: running from scratch it did led to error as you suggested, but it didn't anymore after trying to change the version from 3.3 to 3.7 in order to check the minimum version required for this. After reverting back to 3.7, as shown above, it didn't fail anymore in any case and with any version. |
Has syntax changed since April? Compose file: version: "3.7"
services:
db:
image: hello-world
volumes:
- type: bind
source: ./storage
target: /storage Running: [user@localhost test]# docker-compose up
Creating network "test_default" with the default driver
Pulling db (hello-world:)...
latest: Pulling from library/hello-world
0e03bdcc26d7: Downloading [========> ] 0e03bdcc26d7: Pull complete
Digest: sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec
Status: Downloaded newer image for hello-world:latest
Creating test_db_1 ... error
ERROR: for test_db_1 Cannot create container for service db: invalid mount config for type "bind": bind source path does not exist: /tmp/test/storage
ERROR: for db Cannot create container for service db: invalid mount config for type "bind": bind source path does not exist: /tmp/test/storage
ERROR: Encountered errors while bringing up the project. |
@kirillt does the |
@thaJeztah I see that in last post (@nicolabeghin) folder But is there any way of initializing non-existing folders before mounting them? |
@kirillt I am very curious to this as well. Did you manage to find a solution? |
@jjkoehorst if I remember correctly, no |
Running
docker-compose up
results in creation of directories specified viavolumes
directive on the host system. I think it would be better to error out if the host directory does not exist.The text was updated successfully, but these errors were encountered: