Reputation: 103
I want to create a Docker container and I wrote image. Everything works great except the COPY command where I got confused. My Dockerfile:
RUN HOME=/home/ros rosdep update
RUN mkdir -p /home/ros/workspace
# Copy the files
COPY $PWD/src/a_file /home/ros/workspace/src
COPY $PWD/src/b_file /home/ros/workspace/src
a_file
is a directory like a b_file
. When I try to copy these directories into a newly created directory called /home/ros/workspace/src
I want a_file
and b_file
to be both inside /home/ros/workspace/src
. Instead of this, I get another src
directory /home/ros/workspace/src/src
) and the contents of a_file
and b_file
are inside that directory.
What am I doing wrong?
Upvotes: 3
Views: 3044
Reputation: 3783
As mentioned in other answers, $PWD
refers to the image context.
Try to use .
instead.
To setup your working directory, use WORKDIR
Also, both a_file
and b_file
are in src/
All in all, this should work (not tested):
FROM <your-base-image>
WORKDIR /home/ros
RUN rosdep update
RUN mkdir -p workspace
# Copy the files
COPY ./src workspace/src
Upvotes: 3
Reputation: 10064
In your Dockerfile, PWD variable refers to image context (i.e: inside the image).
From COPY documentation:
paths of files and directories will be interpreted as relative to the source of the context of the build.
If src
directories are in the root of your build context, your example it will be:
...
COPY src/a_file /home/ros/workspace/src
COPY src/b_file /home/ros/workspace/src
...
Upvotes: 1