Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 Compose file 的优化建议, 兼容 arm 架构 (M1 mac) #478

Open
pen4uin opened this issue Dec 15, 2023 · 4 comments
Open

关于 Compose file 的优化建议, 兼容 arm 架构 (M1 mac) #478

pen4uin opened this issue Dec 15, 2023 · 4 comments

Comments

@pen4uin
Copy link

pen4uin commented Dec 15, 2023

环境信息

  • 操作系统: Apple M1
  • Docker 版本: Docker version 24.0.6, build ed223bc
  • Docker-Compose 版本: Docker Compose version v2.22.0-desktop.2

问题描述

部分环境不支持非X86架构的CPU,常见报错:

  • docker-compose process finished with exit code

类似问题可见已有issues:

解决方案

for vulhub

修改 docker compose file 或者在文档中增加该解决方案

  • 修改文件格式版本号为 3
  • 设置 platform 选项 platform: linux/amd64

for vulhub user

具体操作见:run x86 containers on apple mac m1

测试案例

1、jeecg-boot/CVE-2023-4450/docker-compose.yaml

  • vulhub 原始版本
image
  • 优化版本
image

附: docker-compose.yaml

version: '3'
services:
  jeecg-boot-mysql:
    image: mysql:8.0
    platform: linux/amd64
    environment:
      MYSQL_ROOT_PASSWORD: root
    container_name: jeecg-boot-mysql
    command:
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
      --max_allowed_packet=128M
      --default-authentication-plugin=caching_sha2_password

  jeecg-boot-redis:
    image: redis:5.0
    hostname: jeecg-boot-redis

  jeecg-boot-system:
    image: vulhub/jeecg-boot:3.5.3
    depends_on:
      - jeecg-boot-mysql
      - jeecg-boot-redis
    hostname: jeecg-boot-system
    ports:
      - 8080:8080

2、metersphere/plugin-rce/docker-compose.yml

  • vulhub 原始版本
image
  • 优化版本
image

附: docker-compose.yaml

version: '3'

services:
  web:
    image: vulhub/metersphere:1.16.3
    ports:
      - "8081:8081"
      - "5005:5005"
    environment:
      MYSQL_SERVER: db:3306
      MYSQL_DB: metersphere
      MYSQL_USERNAME: root
      MYSQL_PASSWORD: root
      KAFKA_SERVER: kafka:9092
  db:
    image: mysql:5.7
    platform: linux/amd64
    command: --sql-mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" --max-connections=8000
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=metersphere
  kafka:
    image: bitnami/kafka:3.4.1
    platform: linux/amd64
    environment:
      # KRaft settings
      - KAFKA_CFG_NODE_ID=0
      - KAFKA_CFG_PROCESS_ROLES=controller,broker
      - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=0@kafka:9093
      # Listeners
      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093
      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://:9092
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
      - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
      - KAFKA_CFG_INTER_BROKER_LISTENER_NAME=PLAINTEXT
@phith0n
Copy link
Member

phith0n commented Dec 15, 2023

👍可以尝试,不过测试的成本比较高,如果统一增加不知道会不会有问题。

@pen4uin
Copy link
Author

pen4uin commented Dec 16, 2023

测试成本确实会有点高,感觉可以先在 README 的注意事项备注这种解决方案,然后在后续的 compose file 中再做尝试。

@pen4uin pen4uin closed this as completed Dec 22, 2023
@phith0n
Copy link
Member

phith0n commented Dec 22, 2023

我觉得可以保持这个issue的Open状态,作为一个TODO项,之后有机会是可以做的。

@phith0n phith0n reopened this Dec 22, 2023
@bfengj
Copy link

bfengj commented Jan 31, 2024

m1用户可以export DOCKER_DEFAULT_PLATFORM=linux/amd64来解决这个常见的问题,设置了DOCKER_DEFAULT_PLATFORM之后使用docker默认的镜像和容器就都是amd64架构的。我的看法是因为大部分的amd64镜像在m1的mac上都能跑,就一般都开启export DOCKER_DEFAULT_PLATFORM=linux/amd64,遇到amd64不行的(实际上非常少,我几乎没有遇到过),再export DOCKER_DEFAULT_PLATFORM=linux/arm64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants