如何自定义分子的docker图像?

How to customize molecule's docker image?

我正在使用 Molecule 来测试一些 Ansible 角色。我想将一些文件推送到用于测试的 docker 图像。为此,我将测试文件放在 molecule 文件夹中,并将 ADD/COPY 命令添加到 Dockerfile.j2 文件中。我的文件夹结构如下所示:

- ansible-role-foo/
  - molecule/
    - default/
      - Dockerfile.j2
      - myTestFile.txt
      - ...

Dockerfile.j2:

# Molecule managed
...

RUN mkdir -p /my/path
COPY myTestFile.txt /my/path

启动 molecule --debug converge 时,出现以下错误:

COPY failed: stat /var/lib/docker/tmp/docker-builder266739241/myTestFile.txt: no such file or directory

我正在使用 molecule 2.18.1.

如何在分子上下文中正确地将 myTestFile.txt 包含在 docker 图像中?

/var/lib/docker/tmp/docker-builder266739241/myTestFile.txt Obviously, your question has the answer. You should put your text file in the mentioned directory and see if it passes. Otherwise you should try giving the full path where your text file is located. GetFileAttributesEx c:RUN: The system cannot find the file specified.

你也可以直接内联内容:

RUN echo $'\n\
my file content\n\
' > /tmp/myfile