Can't access a volume during building a docker image

自古美人都是妖i 提交于 2020-01-05 05:45:07

问题


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?


回答1:


Sorry, I have just found out that volumes are not accessible during build. They are accessible during run of the container, which is said here in the point 9. But when I changed my Dockerfile to this:

# Dockerfile
FROM ubuntu:14.04
CMD ["ls", "/var/example"]

... it worked perfectly well and printed out all the files inside the example folder.



来源:https://stackoverflow.com/questions/51627401/cant-access-a-volume-during-building-a-docker-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!