Reputation: 165
I want download a private repository from bitbucket, but get some error
fatal: could not read Username for 'https://bitbucket.org': terminal prompts disabled
here my dockerfile
FROM golang:1.17 as build
RUN apt update && apt upgrade -y && \
apt install -y git \
make openssh-client
WORKDIR /src
COPY . .
RUN git config --global url."https://username:[email protected]".insteadOf "https://bitbucket.org"
RUN go mod tidy
RUN go build -o user-management
Upvotes: 1
Views: 2823
Reputation: 11
For me helped add "machine github.com login USERNAME password APIKEY " to $HOME/.netrc
My Dockerfile:
FROM golang:latest as builder
ARG GIT_CONFIG
WORKDIR /builder/
ADD . /builder/
RUN "${GIT_CONFIG}" > $HOME/.netrc
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./cmd/main.go
&& rm -f $HOME/.netrc
FROM scratch
COPY --from=builder /builder/main/ .
Maybe it will help you.
Upvotes: 1
Reputation: 20547
I think it's most clean to use an ssh key for that. You can actually tell docker to use the config from your local ssh agent. You need to enable buildkit for this. See the docs.
eval "$(ssh-agent -s)"
ssh-add /path/to/ssh-key
docker build --ssh default --tag example .
In your Dockerfile, you need to mount this on a specific run instruction:
RUN --mount=type=ssh go mod download
That requires you adding the same ssh key to your private bitbucket repo, so that you can use it to download dependencies.
There are more ways to mount secrets for the lifetime of a run instruction. See the docs.
Upvotes: 4
Reputation: 2993
never do that, you need download the repo outside the docker build
command, and use COPY
to transfer these files into images, when build
Upvotes: -1