Share host's GPG (forward GPG agent) with a Docker container (access host GPG from within a container)

628 Views Asked by At

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
0

There are 0 best solutions below