skip to Main Content

I am getting this message on building a Debian:stretch-slim Docker image with Python 3.7.7:

gpg: keyserver receive failed: Cannot assign requested address
The command '/bin/sh -c set -ex [...]'
[...] returned a non-zero code: 2

I think it’s a GPG or a networking issue.

Any tips? Your assistance is highly appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    Following the recommendation from Laurent Sittler, the solution was on adding options to the gpg servers.

    Find this line in the Dockerfile:

    && gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" 
    

    and replace it with this block:

    && ( 
      gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" 
        || gpg --batch --keyserver pgp.mit.edu --recv-keys "$GPG_KEY" 
        || gpg --batch --keyserver keyserver.pgp.com --recv-keys "$GPG_KEY" 
    ) 
    

  2. UPDATE: Any change in the code has no effect. You need to run your code again until it works (or you add more download locations to go through in an if-statement so that the chance is less that you do not catch a download); see the other answer of this thread.

    I just leave the following old part here as a proof that any placebo code changes did not help me, it was random and it strangely appeared at every first run, while at the second, it usually worked.


    Run

    sudo apt-get update
    

    before you run

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0F164EEB
    

    And if you have an "echo" line before that, run another sudo apt-get update even before that:

    RUN apt-get update
    RUN sh -c 'echo "..." > /etc/...'
    RUN apt-get update
    RUN apt-key adv ...
    

    By this, I got rid of the similar error "Cannot assign requested address":

    Executing: /tmp/apt-key-gpghome.Up2U8vHXpt/gpg.1.sh --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key C1CF6E31E6
    gpg: keyserver receive failed: Cannot assign requested address
    ERROR: Service 'listener' failed to build: The command '/bin/sh -c apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key C1CF6E31E6' returned a non-zero code: 2
    

    Most likely: server is just busy, try again

    This could be a placebo, though, since this answer to the same error, but in another context says that this can appear when the address is just busy. Which would mean: if you have this error, just try again, and sudo apt-get update might not change anything, then. That sounds most likely.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search