Build a Docker image with private repos
To build a Docker image that has dependencies from private repositories, you should pass the .netrc configuration (see more in How to access private repos in Go). Ideally, this configuration should be passed as a secret: FROM golang:1.22.2-alpine3.19 AS deps COPY go.mod go.sum ./ # Copy secrets from /kaniko for Kaniko or from /run/secrets for Podman/Buddah RUN --mount=type=secret,id=netrc \ cp /kaniko/netrc "$HOME"/.netrc || cp /run/secrets/netrc "$HOME"/.netrc && \ go mod download && \ rm "$HOME"/.netrc GitLab CI/CD In GitLab CI, to build the image, you need to create a .netrc configuration with CI_JOB_TOKEN and pass it to Kaniko secrets. Here is an example: ...