Why I'm unable to COPY my files into docker container?
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.
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.