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

2

8

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
Classify answered 30/7, 2017 at 15:56 Comment(0)
S
5

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.

Scilicet answered 30/7, 2017 at 17:8 Comment(5)
Even this is not copying the public-html folder to the container.Classify
Please include the steps you run to build the new image and run your container.Scilicet
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 tryClassify
please check the UPDATE2 in my question for properly formatted response.Classify
I'm using -v so that I do not have to build the image every time I make changes to my code. -v helps me see the changes i do in my project(present in the host) instantly in my host browser. Can you please tell me what you want to pass on by your last sentence?Classify
T
0

Before you can COPY files to different directories other than root, you have to create them.

Update your Dockerfile to the following

FROM httpd:2.4 MAINTAINER Ankit 
MKDIR -p /usr/local/apache2/htdocs/ # Create the directory with '-p' option. 
COPY ./public-html/ /usr/local/apache2/htdocs/

Edit 1

Based on the documentation Docker CP Command, if

DEST_PATH exists and is a directory and if

SRC_PATH does not end with /. (that is: slash followed by dot) the source directory is copied into this directory

SRC_PATH does end with /. (that is: slash followed by dot) the content of the source directory is copied into this directory

In your case /public-html/ does end with a slash, so only the contents must have been getting copied. Updating it to ./public-html should resolve the issue.

Hope this helps.

Trimetric answered 30/7, 2017 at 16:1 Comment(7)
htdocs folder is already present, it is the public-html folder which is not created inside htdocs.Classify
ah! Misread the question. Modify COPY to COPY public-html /usr/local/apache2/htdocs/Trimetric
Nope. that did not work either. + ./public-html/ is required coz it mentions the relative path from the root of my project.Classify
That should not be the case. Are there any other files in your public-html folder that are not getting copied?Trimetric
Only the folders are not getting created. Even the files inside the subfolders of public-html are created in the htdocs folder.Classify
I've tried the edited part as well, unfortunately that doesn't work as well.Classify
Well, i was incorrect to say that subfolder are not copied only the files inside it are copied. I just rechecked and subfolder are copied but the main Folder i.e. public-html folder is not copied into the htdocs.Classify

© 2022 - 2024 — McMap. All rights reserved.