Reputation: 2913
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
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 !
Upvotes: 0
Views: 2197
Reputation: 2913
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!
Upvotes: 1
Reputation: 4125
As I know, you can only use files from the directory where your Dockerfile
is.
You cannot ADD
or COPY
files outside of the path local to the Dockerfile
.
The solution is either mount volume
with docker run
or docker-compose
(what you did already), or copy the directory ~/.ssh/
into your Dockerfile
directory and then run docker build
again.
Let's say we're in /home/saeed/docker/
where your Dockerfile
is located, and it has the following contents:
FROM nginx:alpine
COPY .ssh /root/.ssh
Before running docker build
, copy the required directory into the build directory:
cp -r ~/.ssh .
Then you can build and run your image as normal.
Upvotes: 2