不允许获得“附加属性”。在Docker-Compose中指定SSH-Agent时出错

发布于 2025-02-09 02:58:58 字数 2385 浏览 0 评论 0 原文

我正在尝试构建Python Docker映像,该图像使用SSH从私人存储库安装PIP。其详细信息在需求中。txt文件。

我已经花了很长时间从Stackoverflow阅读指南以及有关该主题的官方Docker文档...

https://docs.docker.com/develop/develop-images/build_enhancements/#using-ssh-to-access-private-数据构建 https://docs.docker.com/compose/compose/compose/compose/compose-file/build/build/build/build/build/build/build- /#ssh

...并提出了一个dockerfile,在使用时构建并运行正常:

$ docker build --ssh default -t build_tester .

但是,当我尝试在docker-compose.yml文件中进行相同操作时,我会收到以下错误

$ docker-compose up

services.build-tester.build Additional property ssh is not allowed

:即使启用buildKit也是相同的:

$ COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose up

services.build-tester.build Additional property ssh is not allowed

项目结构

- docker-compose.yml
- build_files
  - Dockerfile
  - requirements.txt
  - app
    - app.py

dockerfile

# syntax=docker/dockerfile:1.2

FROM python:bullseye as builder

RUN mkdir -p /build/
WORKDIR /build/

RUN apt-get update; \
    apt-get install -y git; \
    rm -rf /var/lib/apt/lists/*

RUN mkdir -p -m 0600 ~/.ssh; \
    ssh-keyscan -H github.com >> ~/.ssh/known_hosts

RUN python3 -m venv env; \
    env/bin/pip install --upgrade pip

COPY requirements.txt .
RUN --mount=type=ssh \
    env/bin/pip install -r requirements.txt; \
    rm requirements.txt

FROM python:slim as runner

RUN mkdir -p /app/
WORKDIR /app/

COPY --from=builder /build/ .
COPY app/ .

CMD ["env/bin/python", "app.py"]

docker-compose.yml

services:
  build-tester:
    container_name: build-tester
    image: build-tester
    build: 
      context: build_files
      dockerfile: Dockerfile
      ssh:
        - default

如果我删除...

ssh:
  - default

... docker-compose 命令构建图像确定,但显然不会以app.py的速度运行。

如果可能的话,我真的希望能够以这种方式进行此操作,因此对任何建议都将不胜感激。

I'm trying to build a Python docker image which pip installs from a private repository using ssh. The details of which are in a requirements.txt file.

I've spent a long time reading guides from StackOverflow as well as the official Docker documentation on the subject ...

https://docs.docker.com/develop/develop-images/build_enhancements/#using-ssh-to-access-private-data-in-builds
https://docs.docker.com/compose/compose-file/build/#ssh

... and have come up with a Dockerfile which builds and runs fine when using:

$ docker build --ssh default -t build_tester .

However, when I try to do the same in a docker-compose.yml file, I get the following error:

$ docker-compose up

services.build-tester.build Additional property ssh is not allowed

This is the same even when enabling buildkit:

$ COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose up

services.build-tester.build Additional property ssh is not allowed

Project structure

- docker-compose.yml
- build_files
  - Dockerfile
  - requirements.txt
  - app
    - app.py

Dockerfile

# syntax=docker/dockerfile:1.2

FROM python:bullseye as builder

RUN mkdir -p /build/
WORKDIR /build/

RUN apt-get update; \
    apt-get install -y git; \
    rm -rf /var/lib/apt/lists/*

RUN mkdir -p -m 0600 ~/.ssh; \
    ssh-keyscan -H github.com >> ~/.ssh/known_hosts

RUN python3 -m venv env; \
    env/bin/pip install --upgrade pip

COPY requirements.txt .
RUN --mount=type=ssh \
    env/bin/pip install -r requirements.txt; \
    rm requirements.txt

FROM python:slim as runner

RUN mkdir -p /app/
WORKDIR /app/

COPY --from=builder /build/ .
COPY app/ .

CMD ["env/bin/python", "app.py"]

docker-compose.yml

services:
  build-tester:
    container_name: build-tester
    image: build-tester
    build: 
      context: build_files
      dockerfile: Dockerfile
      ssh:
        - default

If I remove ...

ssh:
  - default

... the docker-compose up command builds the image OK but obviously doesn't run as app.py doesn't have the required packages installed from pip.

I'd really like to be able to get this working in this way if possible so any advice would be much appreciated.

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

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

发布评论

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

评论(1

美人迟暮 2025-02-16 02:58:58

好的 - 因此最终是一个非常简单的修复程序...只需确保Docker -Compose已更新为Mac上的2.6版。

由于某种原因,Brew无法正确更新我的Docker桶,因此从2022年1月初开始运行包裹。似乎在此之间的某个时候添加了SSH兼容性。

OK - so ended up being a very simple fix... Just needed to ensure docker-compose was updated to version 2.6 on my Mac.

For some reason brew wasn't updating my docker cask properly so was still running a package from early Jan 2022. Seems --ssh compatibility was added sometime between then and now.

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