0

Where is the user's home directory, specifically ~/.ssh, in a python3.* docker image?

I need to add a specific SSH key to an image so it can access a private git repo at run-time.

Articles like this explain how to do this, but it still depends on the underlying image, and I don't know what the "python" image is based on, since it doesn't conform to any standard Linux distro.

Cerin
  • 60,957
  • 96
  • 316
  • 522
  • Strictly speaking, you can put the key anywhere; `~/.ssh` is just the default location. You can adjust whatever command uses the key to look in a specific location. – chepner Jun 25 '21 at 18:29
  • 1
    That said, the standard Python image doesn't have any regular users, only `root` and various services accounts. `/root/.ssh` doesn't exist by default, but you can create it. – chepner Jun 25 '21 at 18:32
  • If you are using some other image, you'll have to give us more details about how the image was created. – chepner Jun 25 '21 at 18:33
  • You really don't want to copy ssh keys into an image, since it's very easy to read them back out. But the answers to the linked questions go through a lot of options (bind mounts, multi-stage builds, buildkit extension options, ...). – David Maze Jun 25 '21 at 18:40
  • In the Docker Hub image pages like the one you link to, the version tags are links to their respective Dockerfiles. "Buster" images are Debian-based, "Alpine" ones are Alpine-based. – David Maze Jun 25 '21 at 18:41
  • @chepner Thanks, that's what I thought but I was looking for confirmation. – Cerin Jun 25 '21 at 18:41
  • @DavidMaze That's a fair point, but not a problem for my use case. The image is only used during a build to run some unittests in a standardized environment, and is immediately thrown away afterwards. – Cerin Jun 25 '21 at 18:43
  • @Cerin Rather than adding them to the image, mount a directory containing the keys when you create the container. – chepner Jun 25 '21 at 18:48

0 Answers0