Home > Mobile >  Unable to copy local directory into Docker container
Unable to copy local directory into Docker container

Time:10-18

I'm very new to a Docker. I want to copy a local directory to a Docker container but I get error

file not found in build context or excluded by .dockerignore: stat ~/.ssh: file does not exist

Here is the line of COPY code,

COPY ~/.ssh /root/.ssh

I can make sure that I have ~/.ssh that it says dose not exist

enter image description here

I need to do this my Application throw error

java.io.FileNotFoundException: /root/.ssh/id_rsa (No such file or directory)

Then I've just realised that I need to copy it into a container.

In my app, I need to use id_rsa and known_hosts to connect to a SFTP server.

Please help. Thanks a lot !

CodePudding user response:

I have not found the reason yet but I found the workaround by mounting the volume in docker-compose instead.

  • ~/.ssh:/root/.ssh

But if someone could find the solution to my COPY problem I'm willing to learn it !

CodePudding user response:

As I know, you can only files from the path where Dockerfile is there.

You cannot ADD or COPY files outside of the path Dockerfile is.

The solution is either mount volume with docker run or docker-compose (what you did already), or copy the directory ~/.ssh/ into Dockerfile path and then run docker build again.

Let's say we're in /home/saeed/docker/ where `Dockerfile with following contents exist:

FROM nginx:alpine
COPY .ssh /root/.ssh

Before we run docker build, I run:

cp -r ~/.ssh .

Then you build and run your image like as you did.

  • Related