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?
1 Answer
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
2 Comments
Soham Mukherjee
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 ?
Shaqil Ismail
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.
RUN ssh-keygenin 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.