I'm new to docker and I'm trying to build a small dockefile for apache just for testing.
FROM httpd:2.2.31
RUN mkdir -p /opt/mw/apache-test/logs
ADD ./httpd-custom.conf /usr/local/apache2/conf/httpd.conf
COPY /opt/mw/apache-2.2.31-instance1/htdocs/ /usr/local/apache2/htdocs/
But for some reason I getting an error with the COPY.
Also, I tried to use ADD.
This is the error I got:
Step 4 : COPY /opt/mw/apache-2.2.31-instance1/htdocs/ /usr/local/apache2/htdocs/
lstat opt/mw/apache-2.2.31-instance1/htdocs/: no such file or directory
What I'm doing wrong?
Multiple DockerfilesStaging and production should be using the same image, built from the same Dockerfile to guarantee that they are as-similar-as-possible.
According to the Dockerfile best practices guide, we should always prefer COPY over ADD unless we specifically need one of the two additional features of ADD. As noted above, using ADD to copy remote files into a Docker image creates an extra layer and increases the file size.
Understand that you do not want to mount the volumes and instead wanted have those files part of the image so that it can be shared. At least assuming this.
As per the Docker documentation
COPY obeys the following rules:
- The path must be inside the context of the build; you cannot COPY ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.
- If is a directory, the entire contents of the directory are copied, including filesystem metadata.
You might got the the problem by now. In your Dockerfile
i.e., COPY
statement is the problem since it is referring to absolute path which is not following the 1st rule from the above. So, htdocs
should be available in the local directory from which you execute the docker build
command.
The following changes need to made before building the image:
Dockerfile
, httpd-custom.conf
files./opt/mw/apache-2.2.31-instance1/htdocs
to current directory. So, that htdocs
directory can be now part of context ( as mentioned in the docs) while building the image.Dockerfile
to the following(mainly COPY command):FROM httpd:2.2.31
RUN mkdir -p /opt/mw/apache-test/logs
ADD ./httpd-custom.conf /usr/local/apache2/conf/httpd.conf
COPY htdocs /usr/local/apache2/htdocs
Now you should be able to build it successfully.
For just demo, used a light weight busybox
and create a directory in the same context (to simulate your case) and it does as you see below:
$ more Dockerfile
FROM busybox
COPY data_folder /opt/data_folder
CMD ["ls", "/opt/data_folder"]
$ ls
data_folder Dockerfile
$ ls data_folder/
test.txt
Build Image:
$ sudo docker build -t dirtest .
Sending build context to Docker daemon 3.584 kB
Step 1 : FROM busybox
---> e02e811dd08f
Step 2 : COPY data_folder /opt/data_folder
---> b6b1a9555825
Removing intermediate container b682e0467803
Step 3 : CMD ls /opt/data_folder
---> Running in 3b05f08ceafc
---> b73190fc1fd9
Removing intermediate container 3b05f08ceafc
Successfully built b73190fc1fd9
Running above Image in a Container which shows directory 'data_folder' is copied and showing its contents. In your case, it is htdocs
$ sudo docker run -it --rm --name testdirtest dirtest
test.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With