如何在macos上构建多平台docker镜像?

问题描述 投票:0回答:1

我尝试在 Mac 上使用多平台构建 docker 映像,但失败了。

我运行的命令:

docker buildx build --platform linux/amd64,linux/arm64 -t brandojazz/lean-dojo:latest --push .

以调试模式登录

❯ docker buildx build --platform linux/amd64,linux/arm64 -t brandojazz/lean-dojo:latest --push .
[+] Building 0.0s (0/0)                                                                                                                     docker:desktop-linux
ERROR: Multi-platform build is not supported for the docker driver.
Switch to a different driver, or turn on the containerd image store, and try again.
Learn more at https://docs.docker.com/go/build-multi-platform/

docker 文件是:

# Use a specific version of kitware/cmake as the base image
FROM kitware/cmake:ci-clang_cxx_modules-x86_64-2023-02-15

# Install required packages: 'which', GMP library development files, Python3, and pip
RUN yum -y install which gmp-devel python3 python3-pip
# Create a symbolic link for python3 as /usr/bin/python for compatibility
RUN ln -s $(which python3) /usr/bin/python
# Install Python packages: toml for TOML file parsing, loguru for logging, tqdm for progress bars
RUN pip3 install toml loguru tqdm

# Set the environment variable ELAN_HOME to store Elan's installation
ENV ELAN_HOME="/.elan"
# Add ELAN_HOME/bin to the PATH for easier access to Elan's binaries
ENV PATH="${ELAN_HOME}/bin:${PATH}"
# Download and execute Elan's installation script in silent mode with auto-approval
RUN curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | bash -s -- -y

# Change permissions to allow writing in the /.elan directory
RUN chmod -R a+w /.elan

# Set the working directory to /workspace for the container
WORKDIR /workspace
# Change permissions to allow writing in the /workspace directory
RUN chmod -R a+w /workspace

我还尝试使用更标准的命令直接构建它,但由于

FROM kitware/cmake:ci-clang_cxx_modules-x86_64-2023-02-15
它在 mac m1 max 中不起作用,例如,

# Build the Image
docker build -t brandojazz/lean-dojo:latest .

# Push the Image to a Docker Registry
docker push brandojazz/lean-dojo:latest

# Start the Docker Container, -d, it runs the container in the background 
docker run -d --name lean-dojo-container brandojazz/lean-dojo:latest
# docker run -it --name lean-dojo-container brandojazz/lean-dojo:latest bash

# Attach to the running Docker container via a terminal CLI bash
docker exec -it lean-dojo-container bash

但我想要的是多平台安装才能工作。


参考:

linux docker
1个回答
0
投票

从 docker 文档的链接:

enter image description here

这样做应该可以解决您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.