"No such file or directory" 这个 Dockerfile 有什么问题?
"No such file or directory" what's wrong in this Dockerfile?
我正在玩 Dockerfile,我有这个:
ARG PUID=1000
ARG PGID=1000
RUN groupadd -g $PGID docker-user && \
useradd -u $PUID -g docker-user -m docker-user && \
mkdir /home/docker-user/.composer
COPY container-files/home/docker-user/.composer/composer.json /home/docker-user/.composer
RUN chown -R docker-user:docker-user /home/docker-user/.composer
USER docker-user
RUN composer global install
但是当我尝试构建图像时,它以以下错误结束:
Step 6 : COPY container-files/home/docker-user/.composer/composer.json /home/docker-user/.composer
lstat container-files/home/docker-user/.composer/composer.json: no such file or directory
根据此输出,文件确实存在于主机上:
$ ls -la workspace/container-files/home/docker-user/.composer/
total 12
drwxrwxr-x 2 rperez rperez 4096 Oct 5 11:34 .
drwxrwxr-x 3 rperez rperez 4096 Oct 5 11:14 ..
-rw-rw-r-- 1 rperez rperez 208 Oct 5 11:20 composer.json
我也尝试过这种语法:
COPY container-files /
但是也没用。所以我应该问:怎么了?为什么这会一次又一次地失败?我在这里缺少什么?
documentation 通过以下方式解决此问题:
By default the docker build command will look for a Dockerfile
at
the root of the build context. The -f
, --file
, option lets you
specify the path to an alternative file to use instead. This is useful
in cases where the same set of files are used for multiple builds. The
path must be to a file within the build context. If a relative path is specified then it is interpreted as relative to the root of the context.
在这种情况下我认为是
COPY workspace/container-files/home/docker-user/.composer/composer.json /home/docker-user/.composer
我正在玩 Dockerfile,我有这个:
ARG PUID=1000
ARG PGID=1000
RUN groupadd -g $PGID docker-user && \
useradd -u $PUID -g docker-user -m docker-user && \
mkdir /home/docker-user/.composer
COPY container-files/home/docker-user/.composer/composer.json /home/docker-user/.composer
RUN chown -R docker-user:docker-user /home/docker-user/.composer
USER docker-user
RUN composer global install
但是当我尝试构建图像时,它以以下错误结束:
Step 6 : COPY container-files/home/docker-user/.composer/composer.json /home/docker-user/.composer
lstat container-files/home/docker-user/.composer/composer.json: no such file or directory
根据此输出,文件确实存在于主机上:
$ ls -la workspace/container-files/home/docker-user/.composer/
total 12
drwxrwxr-x 2 rperez rperez 4096 Oct 5 11:34 .
drwxrwxr-x 3 rperez rperez 4096 Oct 5 11:14 ..
-rw-rw-r-- 1 rperez rperez 208 Oct 5 11:20 composer.json
我也尝试过这种语法:
COPY container-files /
但是也没用。所以我应该问:怎么了?为什么这会一次又一次地失败?我在这里缺少什么?
documentation 通过以下方式解决此问题:
By default the docker build command will look for a
Dockerfile
at the root of the build context. The-f
,--file
, option lets you specify the path to an alternative file to use instead. This is useful in cases where the same set of files are used for multiple builds. The path must be to a file within the build context. If a relative path is specified then it is interpreted as relative to the root of the context.
在这种情况下我认为是
COPY workspace/container-files/home/docker-user/.composer/composer.json /home/docker-user/.composer