1

What I need

I can sign Git commits locally on a host. I want to be able to sign Git commits in a running container too.

How can I share/mount GPG into a container or access from a container host's GPG?

What I tried

I tried to mount directories. Here is a not working Docker Compose:

    volumes:
      - ${HOME}/.gnupg/:/.gnupg/:ro
      - /run/user/$(id -u)/:/run/user/$(id -u)/:ro

With these mounts I still get (executed inside a running container):

$ git commit -m "foobar"
error: gpg failed to sign the data
fatal: failed to write commit object
Nairum
  • 1,217
  • 1
  • 15
  • 36
  • What process is running inside the container that needs to run `git` commands? Can you just run them on the host? – David Maze Jan 30 '23 at 18:13
  • It's unlikely that anything is looking in `/.gnupg` for GnuPG config and key files. Typically, GnuPG looks in `$HOME/.gnupg` (although you can change that by setting the `GNUPGHOME` environment variable), so you would need to mount it in the appropriate location in the container...but you're probably going to run into file ownership issues unless your UID inside the container matches your UID outside the container. – larsks Jan 30 '23 at 18:34
  • @DavidMaze I use Docker for local development. I start a container, connect to its shell, modify the code, and commit/push changes with Git. It is like local development, but all inside a Docker container. – Nairum Jan 30 '23 at 19:29

0 Answers0