I am trying to create a docker container with a volume called 'example', which has some files inside it, but I can't access it during build. Here are the files I am using:
# docker-compose.yml
version: "3"
services:
example:
build: .
volumes:
- "./example:/var/example"
stdin_open: true
tty: true
And:
# Dockerfile
FROM ubuntu
RUN ls /var/example
CMD ["/bin/bash"]
When I run:
sudo docker-compose up
It gives me an error:
ls: cannot access /var/example: No such file or directory
But when I delete the RUN command from the Dockerfile and run sudo docker-compose up
again, and then run:
docker exec -it c949eef14fcd /bin/bash # c949eef14fcd is the id of the created container
ls /var/example
... in another terminal window, there is no error, and I can see all the files of the example directory. Why?