0

I am using an ec2 instance with docker. I am creating a docker file that uses a Nginx image. I have two directories on my ec2 one is called Docker (this is where the Dockerfile is located) and the other main, I want to copy the contents of main into the directory /usr/share/nginx/html using the docker file. I have tried it like this but keep on getting an error of the file/directory not existing.

ADD /home/ec2-user/main/ /usr/share/nginx/html

in the main directory, I just have one file called one.html

BMW
  • 42,880
  • 12
  • 99
  • 116
  • What is your docker build command & from which directory you are running it ? – Pratik Shah May 01 '17 at 04:23
  • I am using a script to do the build command the script is in the same directory as Dockerfile. this is the command in the script docker build -t "corp-nginx" . – Morris Chestnut May 01 '17 at 04:26
  • I think you can only ADD/COPY files from the directory within which the Dockerfile is located. https://docs.docker.com/engine/reference/builder/#add This makes sure that if someone clones/downloads a dockerized project file, they can use docker to run it right away. They wouldn't depend on the existence of files in other directories. – akz May 01 '17 at 04:27
  • So how do I coy a file that is not in the same directory as the Dockerfile? – Morris Chestnut May 01 '17 at 04:28
  • @MorrisChestnut : try to run the command `docker build -t "corp-nginx" /home/ec2-user` from the same directory where you keep Dockerfile. – Pratik Shah May 01 '17 at 04:28
  • Every thing works fine, apart from the copying part. My script is able to create the images and even create containers based on the image, but I am not able to coy the files from the other directory into the nginx directory. – Morris Chestnut May 01 '17 at 04:31
  • You could try some of the workarounds suggested here: http://stackoverflow.com/questions/27068596/how-to-include-files-outside-of-dockers-build-context – akz May 01 '17 at 04:33
  • @akz I will give those a try, another thing is that my Dockerfile has EXPOSE 80 with ENV NGINX_PORT 80, in my launch script I am required to have the running container to map port 80 in the container to port 8080 on the host. How to I accomplish that. – Morris Chestnut May 01 '17 at 04:38
  • ~You should try `EXPOSE 80:8080`.~ Actually I just checked and it doesn't seem like you can. You cannot specify the port to map to on the host machine in the Dockerfile, because there is no way to guarantee that the port will be available on the host machine where you run the image. https://docs.docker.com/engine/userguide/networking/#exposing-and-publishing-ports But, you can specify it in your run command by adding the -p option as the link suggests. – akz May 01 '17 at 04:44
  • this is how I have it and it works docker run -d -p 8080:80 --name corpweb corp-nginx – Morris Chestnut May 01 '17 at 04:55
  • cool, I meant you can't do port mapping in the Dockerfile. You can do it when you run the container. – akz May 01 '17 at 05:00

0 Answers0