Docker容器无法使用Dockerhub进行身份验证,以推动构建docker容器内部的图像

发布于 2025-02-05 06:05:57 字数 1877 浏览 1 评论 0原文

我正在尝试在Docker容器中构建Docker图像。

我正在尝试在主机上使用身份验证的Docker守护程序,以在Dockerhub上推动Docker图像。

我正在使用此Docker实例在主机计算机上运行Docker容器

docker run -v /var/run/docker.sock:/var/run/docker.sock bitcoin-s-build:latest

使用DockerHub正确身份验证。我可以在主机计算机上运行docker push ...并正确推动图像。

我想在docker容器中运行docker push ...,然后使用安装的套接字将图像推到DockerHub。

这样做时,我会收到此错误:

...
#44 exporting manifest list sha256:14472c602ddb92ba1d7c3f8ab0715b807276eaedc16b10230e7f266b2115a3a0 done
#44 pushing layers
#44 pushing layers 0.5s done
#44 ERROR: authorization status: 401: authorization failed

#3 [linux/arm64 internal] load metadata for docker.io/library/ubuntu:latest
------
 > exporting to image:
------
error: failed to solve: authorization status: 401: authorization failed

要明确,我知道 主机上的Docker守护程序已正确身份验证。

这是我正在用于构建的dockerfile

FROM hseeberger/scala-sbt:17.0.2_1.6.2_2.13.8

WORKDIR /build

RUN apt-get update && apt-get install -y git \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

RUN mkdir -p /etc/apt/keyrings

RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg

# https://docs.docker.com/engine/install/debian/
RUN echo \
      "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
      $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

RUN cat /etc/apt/sources.list.d/docker.list

RUN apt-get update

RUN apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin runit-systemd

RUN git clone --depth 1 https://github.com/bitcoin-s/bitcoin-s.git

WORKDIR "/build/bitcoin-s"

ENTRYPOINT ["sbt", "appServer/docker:publish"]

我在做什么错?

I am trying to build a docker image inside of a docker container.

I'm am attempting to use the an authenticated docker daemon on the host machine to push the docker image on dockerhub.

I'm running the docker container with

docker run -v /var/run/docker.sock:/var/run/docker.sock bitcoin-s-build:latest

This docker instance on the host machine is authenticated correctly with dockerhub. I can run docker push ... on the host machine and correctly push an image.

I would like to run the docker push ... in the docker container, and use the mounted socket to push the image to dockerhub.

When doing so I get this error:

...
#44 exporting manifest list sha256:14472c602ddb92ba1d7c3f8ab0715b807276eaedc16b10230e7f266b2115a3a0 done
#44 pushing layers
#44 pushing layers 0.5s done
#44 ERROR: authorization status: 401: authorization failed

#3 [linux/arm64 internal] load metadata for docker.io/library/ubuntu:latest
------
 > exporting to image:
------
error: failed to solve: authorization status: 401: authorization failed

To be clear, I know the docker daemon on the host machine is properly authenticated.

here is the Dockerfile I am using for the build

FROM hseeberger/scala-sbt:17.0.2_1.6.2_2.13.8

WORKDIR /build

RUN apt-get update && apt-get install -y git \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

RUN mkdir -p /etc/apt/keyrings

RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg

# https://docs.docker.com/engine/install/debian/
RUN echo \
      "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
      $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

RUN cat /etc/apt/sources.list.d/docker.list

RUN apt-get update

RUN apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin runit-systemd

RUN git clone --depth 1 https://github.com/bitcoin-s/bitcoin-s.git

WORKDIR "/build/bitcoin-s"

ENTRYPOINT ["sbt", "appServer/docker:publish"]

What am i doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍暮颜 2025-02-12 06:05:57

我认为您应该使用Docker登录命令,要将图像推到Docker Hub或尝试在项目中使用Shell Program并将每个命令包含在Shell中,以便所有内容都可以自动部署

:例如:
外壳程序将是shell.sh。

Docker登录。

docker build -t“名称”。
Docker标签名称Hubuser/名称:标签。

Docker推Hubuser/名称:标签。

在Docker文件中使用CMD [“ SH”,“ Shell.sh”]。

并在交互式模式下运行容器。
Docker Run -IT -P 0000:0000-名称容器ImageName。

我希望它对您有帮助。

I think you should use docker login command for which you want to push image to docker hub or try to use shell program in project and include each commands in shell so that everything will deploy automatically

For example:
shell program will be shell.sh.

docker login.

docker build -t "name".
docker tag name hubuser/name:tag.

docker push hubuser/name:tag.

And in Docker file use CMD ["sh", "shell.sh"].

and run container in interactive mode.
docker run -it -p 0000:0000 --name container imagename.

I hope it will help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文