Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker `COPY` file not working

Tags:

docker

I have a relatively simple dockerfile

FROM python:3.6.5-alpine

COPY somebinary /usr/local/bin/

COPY install.sh /install.sh
RUN /install.sh

The binary gets copied across just fine (when I run the container to check) but the script doesn't seem to get copied across so that when I try to run it I get:

Step 4/5 : COPY install.sh /install.sh
 ---> 38ecc6dbad13
Step 5/5 : RUN /install.sh
 ---> Running in 0b06962d6e1b
/bin/sh: /install.sh: not found
The command '/bin/sh -c /install.sh' returned a non-zero code: 127

The same happens with any other test files I make, they aren't available when the image is run. Other people have had success running the exact same script so I suspect it could be to do with the fact that I'm running docker through Git Bash on Windows? Could it be a permissions thing?

e: I went and tried running through powershell and got the same error, so perhaps git bash is a red herring

like image 357
ptr Avatar asked May 22 '18 06:05

ptr


People also ask

How do I copy a file in Docker?

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.

How does copy work in Docker?

COPY and ADD are both Dockerfile instructions that serve similar purposes. They let you copy files from a specific location into a Docker image. COPY takes in a src and destination. It only lets you copy in a local or directory from your host (the machine-building the Docker image) into the Docker image itself.

How do I copy a docker image manually?

In order to transfer a Docker image from one server to another, what you need to do is first export the image to a file, then copy that file over from your current server to the new one using scp or rsync and finally load the image to your new server.


1 Answers

It seems your install.sh script is having ^M characters.
Try saving your install.sh into unix format. dos2unix

Use notepad++ or sublime or any other editor which support converting end of lines from Windows to UNIX format.

like image 110
fly2matrix Avatar answered Oct 05 '22 16:10

fly2matrix