0

每当我尝试使用我放置的包装脚本来构建我的 Docker 映像时,我都会遇到一个问题,该脚本允许使用主机环境变量进行适当的 ENV 替换。

每当我执行我的脚本时,我都会收到错误消息:

[+] Building 0.1s (2/2) FINISHED                                                                                                                                                                                                                                                      
 => [internal] load build definition from 63                                                                                                                                                                                                                                     0.1s
 => => transferring dockerfile: 47B                                                                                                                                                                                                                                              0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                0.1s
 => => transferring context: 2B                                                                                                                                                                                                                                                  0.0s
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount2556703017/pipe:[1080734]: no such file or directory
Unable to find image 'my-image:latest' locally
docker: Error response from daemon: pull access denied for gotk-st24-test, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.

这是包装脚本

#!/bin/env bash
# Make sure you have the appropriate token in your ENV variables on a machine that you're running this script on.
DOCKER_BUILDKIT=1 docker build --no-cache  -f <(envsubst < ./Dockerfile) -t "my-image" .
docker run -d -t my-image $1

这是Dockerfile

FROM fluxcd/fluxctl:1.24.3 as builder

ARG ARCH=linux/amd64
ARG KUBECTL_VER=1.22.2
ARG GH_CLI_VER=2.2.0

RUN curl -sL https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VER}/bin/${ARCH}/kubectl \
    -o /usr/local/bin/kubectl && chmod +x /usr/local/bin/kubectl

RUN curl -sL https://github.com/cli/cli/releases/download/v${GH_CLI_VER}/gh_${GH_CLI_VER}_linux_amd64.tar.gz \
    | tar xvz -C /tmp && mv /tmp/gh_${GH_CLI_VER}_linux_amd64/bin/gh /usr/local/bin/ && chmod +x /usr/local/bin/gh && \
    rm -rf /tmp/gh_*

FROM k8s.gcr.io/git-sync/git-sync:v3.3.5 as gitsync

FROM alpine:3.14 as gtk-cli

RUN apk update && apk add coreutils git
ENV GITHUB_TOKEN=$GITHUB_TOKEN

COPY --from=builder --chmod=755 /usr/local/bin/kubectl /usr/local/bin/
COPY --from=builder --chmod=755 /usr/local/bin/fluxctl /usr/local/bin/
COPY --from=builder --chmod=755 /usr/local/bin/gh /usr/local/bin/
COPY --from=gitsync --chmod=755 /git-sync /usr/local/bin/
COPY --chmod=755 ./ssh-entrypoint.sh /ssh-entrypoint.sh
COPY --chmod=755 ./docker-entrypoint.sh /docker-entrypoint.sh

RUN kubectl version --client=true && fluxctl version && gh version
WORKDIR /
ENTRYPOINT [ "/docker-entrypoint.sh" ]

我真的很感激这里的一些帮助。

谢谢大家!

4

0 回答 0