Home > Blockchain >  Docker COPY destination path not found
Docker COPY destination path not found

Time:05-08

I am trying to COPY a source file that is locally present to a destination path that is dynamically passed using the docker ARG command.

Example dockerfile is:

$ cat mydockerfile
FROM debian:latest
RUN apt update
ENV app_env='prod'
ARG src_app_dir
ARG dest_app_dir
RUN echo ${src_app_dir}
RUN echo ${dest_app_dir}
RUN mkdir /root/${dest_app_dir}
COPY ${src_app_dir}/file.txt /root/${dest_app_dir}/filenew.txt
WORKDIR /
CMD ["bash"]

I am trying to pass the build arg dest_app_dir="server_app_dir" and expecting the build process creates the container path /root/server_app_dir/

The source folder is already present on my local machine and where the docker-build context is present.

$ ls -d local_app_dir/
local_app_dir/
$ ls local_app_dir/
file.txt

But I am getting the following error for the destination path:

 $ docker image build --build-arg src_app_dir="local_app_dir" dest_app_dir="server_app_dir" --tag arg_env:1.0 --file mydockerfile
unable to prepare context: path "dest_app_dir=server_app_dir" not found

Does not it work that way or am I missing the correct concept/usage of Docker build ARG and COPY commands here?

I am using docker-desktop on Windows11.

 $ docker version
Client: Docker Engine - Community
 Cloud integration: v1.0.23
 Version:           20.10.14
 API version:       1.41
 Go version:        go1.16.15
 Git commit:        a224086
 Built:             Thu Mar 24 01:48:21 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop
 Engine:
  Version:          20.10.14
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.15
  Git commit:       87a90dc
  Built:            Thu Mar 24 01:46:14 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.5.11
  GitCommit:        3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc:
  Version:          1.0.3
  GitCommit:        v1.0.3-0-gf46b6ba
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

CodePudding user response:

You need to specify the build-arg as many times as the arguments

docker image build --build-arg src_app_dir="local_app_dir" --build-arg dest_app_dir="server_app_dir" --tag arg_env:1.0 --file mydockerfile .

Example

enter image description here


EDIT: Forgot to add context. Thanks @BMitch

  • Related