How to use the mounted ssh in docker for subsequent commands in Dockerfile

Viewed 9607

I have to do a git push while running my container using CMD. But the ssh is not available in the last line i.e in the CMD part, to do a git push. What can I do here to get the ssh key for git push? Someone please help me.

Please find my Dockerfile

# syntax = docker/dockerfile:1.0-experimental
FROM continuumio/anaconda3

# Install git
RUN apt-get update && apt-get install -y git

# Download public key for github.com
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts

# Clone private repository
RUN --mount=type=ssh git clone git@github.com:myorg/myproject.git myproject

CMD python myproject/src/example.py && git push

Then I use the following command to pass my ssh key during run

docker build --ssh default .
1 Answers
Related