Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile COPY from a Windows file system to a docker container

Tags:

I have a simple Dockerfile:

FROM php:7.1-apache LABEL maintainer="[email protected]" COPY C:/Users/rburton/code/MyAgsourceAPI /var/www 

It is the last line that is giving me problems. I am copying from a Windows structure to a docker container (Linux I assume). When I build this image I get:

... Step 3/3 : COPY C:/Users/rburton/code/MyAgsourceAPI /var/www COPY failed: stat /var/lib/docker/tmp/dockerbuilder720374851/C:/Users/rburton/code/MyAgsourceAPI: no such file or directory 

First, something is preventing the recognition that this is an absolute path and naturally if the path is pre-pended with /var/lib/docker/tmp/dockerbuilder720374851 then the file will not be found. Second, I have tried / and \ but all with the same result. Also the drive letter I suspect is confusing to docker. So the question is how do I copy files and folders (along with the contents) from a Windows folder to a docker container?

like image 396
Kevin Burton Avatar asked Sep 19 '17 20:09

Kevin Burton


People also ask

Can you copy a file from local to run container?

The Docker cp command can be used to copy files and directories from the host machine to a container and vice-versa. To copy one single file from the host to container, you can use the command below. You can use the container ID as well. To find the name of the container or ID, you can list all the containers.

Can you copy a file into a Docker image?

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.


1 Answers

First, change your Dockerfile to:

FROM php:7.1-apache LABEL maintainer="[email protected]" COPY MyAgsourceAPI /var/www 

Then, to go your code directory: cd Users/rburton/code.

Within that directory, run: docker build -t <image_name> .

like image 53
ItayB Avatar answered Oct 24 '22 14:10

ItayB