1

Is there any way to generate SSH keys during docker build, and access the keyfile path inside an application running in the container? My application needs the keyfile_path to run. If it isn't possible to dynamically generate keys during build time and use it in the application, what would be the alternative to inject SSH keys from local host to be able to use it in a remote application?

  • Remember that anything that's in the Docker image is pretty easy to get back out; if you `RUN ssh-keygen` in the Dockerfile, that would include your private key. Both paths are possible but it'd be better practice to create the ssh key pair on the host and inject it using a bind mount. – David Maze Jun 02 '21 at 11:07

1 Answers1

0

you should be able to use the RUN command, which is run in a shell, in your dockerfile to generate your SSH key, set permissions on the key after as well.

More information on the RUN command in the following Docker documentation, https://docs.docker.com/engine/reference/builder/#run

Shaqil Ismail
  • 1,794
  • 1
  • 4
  • 5
  • Yeah I'll have a look, but say I need to use a key in the application which exists in my local machine and I want to be able to deploy the application in a remote environment, is there a way to use the key which now rests only with a local host ? – Soham Mukherjee Jun 02 '21 at 11:03
  • I think you would create a network share in the local machine with the key, and then you would create a Docker volume to be able to access the key. – Shaqil Ismail Jun 02 '21 at 11:12