Reputation: 1839
Maybe I'm just not understanding correctly but I'm trying to visually verify that I have used volumes properly.
In my docker-compose I'd have something like
some-project:
volumes:
- /some-local-path/some-folder:/v-test
I can verify it's contents via "ls -la /some-local-path/some-folder"
In some-projects Dockerfile I'd have something like
RUN ls -la /v-test
which returns 'No such file or directory"
Is this the correct way to use it? If so, why can't I view the contents from inside the container?
Upvotes: 0
Views: 3202
Reputation: 160073
Everything in the Dockerfile
runs before anything outside the build:
block in the docker-compose.yml
file is considered. The image build doesn't see volumes or environment variables that get declared only in docker-compose.yml
, and it can't access other services.
In your example, first the Dockerfile
tries to ls
the directory, then Compose will start the container with the bind mount.
If you're just doing this for verification, you can docker-compose run
a container with most of its settings from the docker-compose.yml
file, but an alternate command:
docker-compose run some-project \
ls -la /v-test
(Doing this requires that the image's CMD
is a well-formed shell command; either it has no ENTRYPOINT
or the ENTRYPOINT
is a wrapper script that ends in exec "$@"
to run the CMD
. If you only have ENTRYPOINT
, change it to CMD
; if you've split the command across both directives, consolidate it into a single CMD
line.)
Upvotes: 3