构建Docker映像期间无法访问卷 [英] Can't access a volume during building a docker image

查看:104
本文介绍了构建Docker映像期间无法访问卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个名为 example的卷的Docker容器,其中包含一些文件,但是在构建期间无法访问它。这是我正在使用的文件:

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

并且:

# Dockerfile
FROM ubuntu
RUN ls /var/example
CMD ["/bin/bash"]

当我运行时:

sudo docker-compose up

它给了我一个错误:

ls: cannot access /var/example: No such file or directory

但是当我从Dockerfile中删除RUN命令并运行 sudo docker-compose up ,然后运行:

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?

推荐答案

对不起,我刚刚发现在构建过程中无法访问卷。在容器运行过程中可以访问它们,在第9点中 >。但是,当我将Dockerfile更改为此:

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.

这篇关于构建Docker映像期间无法访问卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆