Larry Cai
Larry Cai

Reputation: 59963

Remove $GNUPGHOME error during Dockerfile build

I build the rabbitMQ alpine docker image locally, see complete Dockerfile

RUN export GNUPGHOME="$(mktemp -d)" \
    && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
    && gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
    && rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc 

And randomly I got error below (mostly in jenkins CI system)

rm -rf /tmp/tmp.bBBnjn rabbitmq-server.tar.xz.asc
rm: can't remove '/tmp/tmp.bBBnjn/S.gpg-agent.extra': No such file or directory

or

rm -rf /tmp/tmp.GlfNBI rabbitmq-server.tar.xz.asc
rm: can't remove '/tmp/tmp.GlfNBI/S.gpg-agent.ssh': No such file or directory

It looks like the gpg agent is just stopped during rm. (It exists when to delete, but disappear when delete happens)

I use Ubuntu 16.04 LTS version

$ docker info
Containers: 2
 Running: 2
 Paused: 0
 Stopped: 0
Images: 193
Server Version: 1.12.6
Storage Driver: overlay
 Backing Filesystem: extfs
Logging Driver: json-file
Cgroup Driver: cgroupfs
..

Any solution for this ?

Upvotes: 2

Views: 1392

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146510

Change it to below and it should work all the time

export GNUPGHOME="$(mktemp -d)"; \
        gpg --keyserver pgp.mit.edu --recv-keys "$GPG_KEY" || \
        gpg --keyserver keyserver.pgp.com --recv-keys "$GPG_KEY" || \
        gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" ; \
    gpg --batch --verify rabbitmq-server.tar.xz.asc rabbitmq-server.tar.xz; \
    pkill -9 gpg-agent; \
    pkill -9 dirmngr; \
    rm -rf "$GNUPGHOME";

gpg-agent and dirmngr run in background and at times takes time to exist. I believe rm picks up the files of these process and when it tries to delete the daemon and files area already gone. So adding these two pkill should remove the error

HTOP

Upvotes: 4

Related Questions