Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I'm unable to COPY my files into docker container?

I'm trying to move my files into htdocs folder of an apache image. Her's what my dockerfile looks like:

FROM httpd:2.4
MAINTAINER Ankit
COPY ./public-html/ /usr/local/apache2/htdocs/

But the COPY command is not copying the files into the container. Here's the output - index.html is there by default, what I'm trying to copy is public-html folder:

root@8453b6ffa6fd:/usr/local/apache2/htdocs# ls
index.html

Is there something I'm missing?

UPDATE: The public-html folder is not getting copied but the file index.html is being copied there, what is the reason for such behaviour?

UPDATE2: Here's my latest dockerfile, command to build and run container.

Dockerfile:
FROM httpd:2.4
MAINTAINER Ankit
COPY public-html/ /usr/local/apache2/htdocs/public-html/

docker build -f Dockerfile -t apache .
docker run -d --name apws -v /Users/ankitsahu/workspace/docker_practi
ce/public-html:/usr/local/apache2/htdocs/ -p 80:80 apache

and when i check the content using exec command:

root@b54e53a231b7:/usr/local/apache2/htdocs# ls -a
.  ..  index.html  sample.html  try
like image 715
Ankit Sahu Avatar asked Jul 30 '17 15:07

Ankit Sahu


People also ask

How do I copy a file into a docker container?

Obtain the name or id of the Docker container. Issue the docker cp command and reference the container name or id. The first parameter of the docker copy command is the path to the file inside the container. The second parameter of the docker copy command is the location to save the file on the host.

Can you copy a file into a docker image?

Dockerfile Dockerfiles are used to build Docker images, which are then instantiated into Docker containers. Dockerfiles can contain several different instructions, one of which is COPY. The COPY instruction lets us copy a file (or files) from the host system into the image.

How do I copy files from local machine to docker container in Windows?

You can use the docker cp command to copy the file. The first path (Source) is the path in the Docker Container and the second one is the path inside your Local System (Destination).


1 Answers

If you are trying to copy the directory public-html into the directory /usr/local/apache2/htdocs to have an .../htdocs/public-html/ directory, then use the following:

COPY public-html/ /usr/local/apache2/htdocs/public-html/

By default, copying a directory will copy the contents of that directory, so you need to name it in the target for the directory to appear.


Edit: Your run command contains a volume that will replace the image contents of this directory:

docker run -d --name apws -v /Users/ankitsahu/workspace/docker_practice/public-html:/usr/local/apache2/htdocs/ -p 80:80 apache

If you want to see what's inside the image, do not use the volume:

docker run -d --name apws -p 80:80 apache

If instead you want to use the volume, then modify the contents of /Users/ankitsahu/workspace/docker_practice/public-html on your docker host.

like image 181
BMitch Avatar answered Oct 11 '22 08:10

BMitch