Problem building docker image with maxmind-geolocation module

1. The problem I’m having:

I wanted to upgrade my caddy install to the latest version. I also use maxmind-geolocation for geoblocking, so I have a Dockerfile to build a caddy image and install the module. That worked before, but now I get an error when trying to build it, no matter if I use an old version of caddy or the latest one.

2. Error messages and/or full log output:

~/d/caddy (main) [1]> sudo docker compose build
WARN[0000] /home/einmaulwurf/docker/caddy/compose.yaml: `version` is obsolete 
[+] Building 31.4s (7/8)                                                                                                                                        docker:default
 => [caddy internal] load build definition from Dockerfile                                                                                                                0.0s
 => => transferring dockerfile: 213B                                                                                                                                      0.0s
 => [caddy internal] load metadata for docker.io/library/caddy:2.8.0                                                                                                      1.1s
 => [caddy internal] load metadata for docker.io/library/caddy:2.8.0-builder                                                                                              1.1s
 => [caddy internal] load .dockerignore                                                                                                                                   0.0s
 => => transferring context: 2B                                                                                                                                           0.0s
 => CACHED [caddy builder 1/2] FROM docker.io/library/caddy:2.8.0-builder@sha256:93a0320af6e247362974f8606f1659b977b8c4421282682844a197b26b4be924                         0.0s
 => => resolve docker.io/library/caddy:2.8.0-builder@sha256:93a0320af6e247362974f8606f1659b977b8c4421282682844a197b26b4be924                                              0.0s
 => CACHED [caddy stage-1 1/2] FROM docker.io/library/caddy:2.8.0@sha256:ccdad842a0f34a8db14fa0671113f9567d65ba3798220539467d235131a3ed63                                 0.0s
 => => resolve docker.io/library/caddy:2.8.0@sha256:ccdad842a0f34a8db14fa0671113f9567d65ba3798220539467d235131a3ed63                                                      0.0s
 => ERROR [caddy builder 2/2] RUN xcaddy build --with github.com/porech/caddy-maxmind-geolocation                                                                        30.3s
------                                                                                                                                                                         
 > [caddy builder 2/2] RUN xcaddy build --with github.com/porech/caddy-maxmind-geolocation:                                                                                    
0.220 2024/05/31 14:19:57 [INFO] absolute output file path: /usr/bin/caddy                                                                                                     
0.221 2024/05/31 14:19:57 [INFO] Temporary folder: /tmp/buildenv_2024-05-31-1419.1687159840                                                                                    
0.221 2024/05/31 14:19:57 [INFO] Writing main module: /tmp/buildenv_2024-05-31-1419.1687159840/main.go                                                                         
0.221 package main                                                                                                                                                             
0.221 
0.221 import (
0.221   caddycmd "github.com/caddyserver/caddy/v2/cmd"
0.221 
0.221   // plug in Caddy modules here
0.221   _ "github.com/caddyserver/caddy/v2/modules/standard"
0.221   _ "github.com/porech/caddy-maxmind-geolocation"
0.221 )
0.221 
0.221 func main() {
0.221   caddycmd.Main()
0.221 }
0.221 2024/05/31 14:19:57 [INFO] Initializing Go module
0.221 2024/05/31 14:19:57 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod init caddy 
0.243 go: creating new go.mod: module caddy
0.246 go: to add module requirements and sums:
0.246   go mod tidy
0.247 2024/05/31 14:19:57 [INFO] Pinning versions
0.248 2024/05/31 14:19:57 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v github.com/caddyserver/caddy/v2@v2.8.0 
30.26 go: github.com/caddyserver/caddy/v2@v2.8.0: Get "https://proxy.golang.org/github.com/caddyserver/caddy/v2/@v/v2.8.0.info": dial tcp: lookup proxy.golang.org: i/o timeout
30.26 2024/05/31 14:20:27 [FATAL] exit status 1
------
failed to solve: process "/bin/sh -c xcaddy build --with github.com/porech/caddy-maxmind-geolocation" did not complete successfully: exit code: 1

3. Caddy version:

2.8.0

but the same problem arises for other versions as well.

4. How I installed and ran Caddy:

Using docker.

a. System environment:

b. Command:

sudo docker compose build

c. Service/unit/compose file:

My Dockerfile

FROM caddy:2.8.0-builder AS builder

RUN xcaddy build --with github.com/porech/caddy-maxmind-geolocation

FROM caddy:2.8.0

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

My docker-compose file (I dont think that there’s a problem with that).

version: "3.7"

services:
  caddy:
    build: .
    container_name: caddy
    restart: unless-stopped
    cap_add:
      - NET_ADMIN
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./site:/site
      - ./data:/data
      - ./config:/config
      - ./GeoLite2-Country.mmdb:/etc/caddy/GeoLite2-Country.mmdb

d. My complete Caddy config:

not relevant

5. Links to relevant resources:

not relevant

You appear to have networking issue. Is your DNS proper? Maybe it’s a temporary connectivity issue?

1 Like

I just fixed it. As @Mohammed90 said, I had networking issues. No idea why though, as it did not happen before.

Following this stack-overflow answer fixed my problem: apt get - Docker build "Could not resolve 'archive.ubuntu.com'" apt-get fails to install anything - Stack Overflow

I had to /etc/default/docker and uncomment the DOCKER_OPTS= line.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.