简体   繁体   中英

Adjustment to docker-compose.yml for M1 chip?

I have a docker-compose.yml that builds about 8 containers made up mostly of mysql, postgres, php-nginx and a few other packages that are custom builds. The production version runs on an UBUNTU host, and my development package runs on Mac OS Catalina with an Intel Chip. The whole thing is also maintained in a private repo on Github.

A collaborator has an M1 Mac, and I'll likely upgrade to an M1 Mac shortly, either a MacBook Pro or the 27" iMac when those are released maybe later this year.

We tried installing the package on his M1 Mac and ran into a few problems, and likely more.

One issue appears to be related to the MySQL build in the compose file (some items removed)

  mysql_db:
    image: mysql:8.0.26
    container_name: mysql_db
    command:
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
      --max-allowed-packet=67108864
      #--general-log=TRUE
      #--general-log-file=/var/lib/mysql/mysql-log.log
    restart: unless-stopped
    ports:
      - "3333:3306"
    healthcheck:
      test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD
    security_opt:
      - seccomp:unconfined
    tty: true
    environment:
      TZ: ""
      MYSQL_ROOT_PASSWORD: ''
      MYSQL_USER: ''
      MYSQL_PASSWORD: ''
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql

    volumes:

      - ./MySQL_DB:/var/lib/mysql/
      - ./mysql_init:/docker-entrypoint-initdb.d

and it looks like there are a couple of ways to resolve that as suggested here:

Docker (Apple Silicon/M1 Preview) MySQL "no matching manifest for linux/arm64/v8 in the manifest list entries

and here:

https://dev.to/lakhansamani/create-docker-image-on-apple-silicon-m1-mac-2f75

by specifiying --platform linux/amd64 on the CLI or platform: linux/amd64 in the compose file.

In one of my DockerFiles I also have:

COPY wkhtmltox_0.12.6-1.buster_amd64.deb /
RUN dpkg -i wkhtmltox_0.12.6-1.buster_amd64.deb

which is a debian package for wkhtmltopdf (with I think the QT support)

There are downloads for the pre-built packages here:

https://wkhtmltopdf.org/downloads.html

There is an ARM64 version of that package available there.

Just trying to figure out how to configure the build (docker-compose.yml, DockerFiles, etc.) so that it'll build on basically any architecture.

If there is a way to detect the architecture in the docker-compose.yml and DockerFiles, that would probably be best so that it could build the proper mysql package and use the proper debian package for whtmltopdf. I suspect that I might run into additional issues with php, postgres and nginx builds, but we haven't gotten that far yet.

The collaborator also has a Windows machine, and I think that will work, but I'll be moving onto an M1 Mac myself shortly.

Just looking for the best way to handle that so we don't have to keep separate builds for the different architectures.

This is a bit more detailed:

https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/

In my case, it may be that the.deb package variation might be the only other item that needs to be fixed, and maybe I could use apt-get for that instead, but I would lose the QT support for that maybe.

Newer answer: There is now an arm64 image

There is now an arm64 image for MySQL 8 on DockerHub:
https://hub.docker.com/r/arm64v8/mysql/

Why not use platform linux/x86_64?

The answer used to be that there was no official arm64 MySQL 8 image, and the workaround was to specify platform: linux/x86_64

However, that runs x86 code on the arm64 M1 via emulation,
so you're taking a performance hit if you still use this way.

For M1 processor you have to specify platform

services:
  mysql_db:
    platform: linux/x86_64
    image: mysql:8.0.26

Alternatively you could use MariaDB for development.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM