最开始的Mac用的是intel的cpu,后来使用了基于Arm架构自研的苹果芯片,在使用虚拟化时需要使用支持Arm架构的镜像。在日常使用中经常会使用Docker来构建一些环境,便发现有时候需要自己去构建镜像或者官方提供的镜像并没有支持Arm架构的,所以需要参考官方Github仓库上的Dockerfile来构建适合Arm架构的镜像。以下记录了在使用MacBook过程中用到的一些比较基础的镜像。
个人环境:M2 + OrbStack
1、maven3 jdk8镜像:maven:3-openjdk-8
镜像的操作系统是debain,并且安装了很多常用包,例如:unzip、curl、wget等。具体可查看
https://hub.docker.com/layers/library/maven/3-openjdk-8/images/sha256-29cc4c106af036b3727fad911174511d5af3103710419e1fd3d0718aa217f7ae?context=explore
有带slim的镜像,如:maven:3-openjdk-8-slim
,镜像体积较小,比不带slim的镜像少一些命令。如果仅用到maven和jdk建议使用带silm的,因为体积小。
2、maven3 jdk11镜像:3-openjdk-11
同上
这个发行的版本有很多。我自己一般使用eclipse-temurin
。因为在Docker Hub上的 Overview 上可以直接点tag
链接,跳转到支持Arm架构的JDK镜像。不用自己在Openjdk那里一页页地找。
1、arm64v8/eclipse-temurin:8-jdk。镜像的操作系统是Ubuntu。
2、arm64v8/eclipse-temurin:8-jre。仅包含java运行环境,镜像更小,操作系统也是Ubuntu。
3、arm64v8/eclipse-temurin:11-jdk。
4、arm64v8/eclipse-temurin:11-jre。
5、arm64v8/eclipse-temurin:17-jdk。
6、arm64v8/eclipse-temurin:17-jre。
等。。。
也可以使用含有maven和jdk的镜像,毕竟可能在构建镜像的时候会需要maven来构建项目。
Nginx的镜像跟eclipse-temurin 一样在Overview上可以看到支持的CPU架构,很轻松就能找到。https://hub.docker.com/r/arm64v8/nginx/tags
例如:1.24.0-alpine3.17-perl
Docker Hub页面
例如:
1、arm64v8/tomcat:8.5-jre8-temurin-focal。看名字大概是基于eclipse-temurin:8-jre-focal镜像的Tomcat 8.5。
2、arm64v8/tomcat:8-jdk8。带有完整jdk8环境
3、arm64v8/tomcat:9.0-jre8-temurin-focal。tomcat9.0版本,jre8运行环境。
4、arm64v8/tomcat:9.0-jdk8-temurin-focal。同理。
等。。。
基本常用的架构都支持。
Mark一下免得再去Docker Hub找:redis:6.2.7
、redis:7.2.3
version: '3.3'
services:
redis6379:
#network_mode: 'host'
image: redis:6.2.7
container_name: redis
# restart: always
#logging:
# driver: 'json-file'
# options:
# max-size: '5g'
ports:
- 6379:6379
volumes:
- ./data:/data
- ./redis.conf:/usr/local/etc/redis/redis.conf
- ./logs:/logs
command: redis-server /usr/local/etc/redis/redis.conf
同redis一样。在Docker Hub上没找到自持Arm架构的5.7版本的MySQL。那就用8.0版本吧。
镜像:mysql:latest
、mysql:8.0.35-bullseye
version: '3'
services:
mysql:
image: mysql:latest
#restart: always
container_name: mysql
hostname: mysql
environment:
MYSQL_ROOT_PASSWORD: 123456
TZ: Asia/Shanghai
ports:
- 3306:3306
volumes:
- ./data:/var/lib/mysql
- ./my.cnf:/etc/mysql/my.cnf
command:
--max_connections=1000
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--default-authentication-plugin=mysql_native_password
healthcheck:
test: ["CMD-SHELL", "curl --silent localhost:3306 >/dev/null || exit 1"]
interval: 10s
timeout: 10s
retries: 3
看了一下Docker Hub上的镜像,latest的镜像不支持arm架构,而且带slim的才支持。Github 上 Nacos Docker仓库
例如:nacos/nacos-server:v2.3.0-slim
、nacos/nacos-server:v1.4.6-slim
或者自行构建:
https://github.com/nacos-group/nacos-docker/blob/master/build/Dockerfile
https://github.com/nacos-group/nacos-docker/blob/master/build/Dockerfile.Slim
参考:https://github.com/nacos-group/nacos-docker/blob/master/example/standalone-derby.yaml
version: "3"
services:
nacos:
image: nacos/nacos-server:v2.2.3-slim
container_name: nacos-standalone
environment:
- PREFER_HOST_MODE=hostname
- MODE=standalone
- NACOS_AUTH_ENABLE=false
- NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789
- NACOS_AUTH_IDENTITY_KEY=123456781099999
- NACOS_AUTH_IDENTITY_VALUE=12345678109999909089
volumes:
- ./standalone-logs/:/home/nacos/logs
- ./init.d/custom.properties:/home/nacos/init.d/custom.properties
ports:
- "8848:8848"
- "9848:9848"
基本上都支持,选择最新的zookeeper:latest
或者指定版本zookeeper:3.8
version: "3"
services:
zookeeper1:
image: zookeeper:3.8
container_name: zoo1
hostname: zoo1
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
- ZOO_SERVER_ID=1
#- ZOO_SERVERS=zoo1:2888:3888;zookeeper2:2888:3888;zookeeper3:2888:3888
volumes:
- "./zoo1/data:/data"
- "./zoo1/datalog:/datalog"
- "./zoo1/conf:/conf"
ports:
- '2181:2181'
- '2888:2888'
- '3888:3888'
1、apache/dubbo-admin:0.5.0-SNAPSHOT,Docker Hub上有,直接拉就行docker pull apache/dubbo-admin:0.5.0-SNAPSHOT
。
2、自行构建,dubbo-admin官方git仓库提供的Dockerfile用到了maven:3-openjdk-8
和openjdk:8-jdk
都是支持Arm架构的。
git clone https://github.com/apache/dubbo-admin.git
cd dubbo-admin/docker/latest
docker build -t apache/dubbo-admin:latest .
version: "3"
services:
dubbo-admin:
image: apache/dubbo-admin:latest
container_name: dubbo-admin
hostname: dubbo-admin
ports:
- '8080:8080'
environment:
- admin.registry.address=zookeeper://127.0.0.1:2181
- admin.config-center=zookeeper://127.0.0.1:2181
- admin.metadata-report.address=zookeeper://127.0.0.1:2181
很遗憾,支持Arm架构的镜像是一个都没有。有一个apache/rocketmq-operator:latest
在K8S上创建RocketMQ的,不太适合在本地使用。
用到的基础镜像是:eclipse-temurin:8-jdk-centos7
支持Arm架构。
git clone https://github.com/apache/rocketmq-docker.git
cd rocketmq-docker/image-build
sh build-image.sh 4.9.4 centos
sh build-image.sh 5.1.4 centos
sh build-image-dashboard.sh 1.0.0 centos
version: '3'
services:
#Service for nameserver
namesrv:
image: apache/rocketmq:4.9.4
container_name: namesrv
ports:
- 9876:9876
volumes:
- ./namesrv/logs:/home/rocketmq/logs
command: sh mqnamesrv
#Service for broker
brokera:
image: apache/rocketmq:4.9.4
container_name: rmqbroker-a
links:
- namesrv
ports:
- 10909:10909
- 10911:10911
- 10912:10912
environment:
- NAMESRV_ADDR=namesrv:9876
volumes:
- ./data-a/broker/logs:/home/rocketmq/logs
- ./data-a/broker/store:/home/rocketmq/store
- ./data-a/broker/conf/broker.conf:/opt/rocketmq-ROCKETMQ_VERSION/conf/broker.conf
command: sh mqbroker -c /opt/rocketmq-ROCKETMQ_VERSION/conf/broker.conf
#Service for another broker -- broker1
brokerb:
image: apache/rocketmq:4.9.4
container_name: rmqbroker-b
links:
- namesrv
ports:
- 10929:10909
- 10931:10911
- 10932:10912
environment:
- NAMESRV_ADDR=namesrv:9876
volumes:
- ./data-b/broker/logs:/home/rocketmq/logs
- ./data-b/broker/store:/home/rocketmq/store
- ./data-b/broker/conf/broker.conf:/opt/rocketmq-ROCKETMQ_VERSION/conf/broker.conf
command: sh mqbroker -c /opt/rocketmq-ROCKETMQ_VERSION/conf/broker.conf
# service for rocketmq dashboard
dashboard:
image: apache/rocketmq-dashboard:1.0.0-centos
container_name: dashboard
ports:
- 8989:8080
links:
- namesrv
depends_on:
- namesrv
environment:
- NAMESRV_ADDR=namesrv:9876
…