Docker refuse to use ssh key despite mounting it as a volume

I am trying to use git within the container without needing to sign to it everytime so I generated ssh key and tried mounting them as volume bs it gives me an error denied access to public key

What is your exact full error message? Public key should be accessible, but private keys must be readable only by the owneer, If you generated the keys on Windows and mounted into a Linux container, that means your keys are probably readable by everyone. Although you wrote in the title you mounted the keys “as a volume”, if it is actually a bind mount where you mount a folder from the host that might not work. The best way is to generate the keys in a container into an actual named volume and mount that in the container where you need it.

Note that the keys must have the right ownet as well. If you generate the keys with a user who has the UID 1000 and then try to use that in a container in which the UID is 1002, that will not work either.

Furthermore, I think it makes sense to share the Dockerfile and the command/compose file that triggers the build.

I mounted the ssh folder like this

And the error i got the the private key is too open and permission denied to public key

Ps:i am working on docker windows so my question what is the right way to do it ?

Please show us you Dockerfile as well, as the key to use a volume during build must be in there. The volumes in the compose file are just runtime configurations, not build time configurations.

this is the docker file :

FROM node:16.17.0
# Add a work directory
# Copy app files
COPY . .
RUN chmod +x
# Expose port

this the

set -e
# Remove a potentially pre-existing for Rails.
rm -f /app/tmp/pids/
yarn install
# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"

this docker-compose.yml :

version: "3.5"
    build: .
    entrypoint: /app/
    command: yarn start
      - .:/app
      - node_modules:/app/node_modules
      - ~/.ssh:/root/.ssh:ro
      - 3001:3000
    name: connection
    external: true

i made a wrong assumption: I thought you try to clone the repo during image build…
though, I don’t see any git related command in either your Dockerfile nor in your entrypoint script.

Your compose file misses a - for the last entry in the volumes sequence. I am surprised docker compose didn’t complain about it…

Also you need to make sure that you follow the suggestions @rimelek made in his response.

I have already told you the only think I could recommend. Please, read my previous post again and ask about the part that you don’t understand so I can explain it an other way.

However @meyay noticed what I could not. That missing “-” before the volume mapping should have given you a syntax error. It is not just invalid compose file, but an invalid YAML file. Maybe you just tried something to fix the problem and forgot to remove that part before sharing. If it happened, make sure you always share the code that you have tested.