Creating and managing Docker containers on Apple Silicon (M1) devices can present unique challenges, especially when it comes to using images that may not have ARM64/v8 architecture support, such as MySQL. This tutorial provides solutions for running MySQL on Apple Silicon (M1) devices using Docker, drawing from community-provided answers.
Understanding the Problem
When attempting to pull and run MySQL images on Apple Silicon (M1) devices, you might encounter the following error:
no matching manifest for linux/arm64/v8 in the manifest list entries
This error occurs because the requested image does not have a version compiled for the ARM64 architecture, which is used by Apple Silicon (M1) chips.
Solution 1: Specifying the Platform
A temporary workaround is to specify the platform for your service in the docker-compose.yml
file to use the x86_64
architecture under emulation. This approach allows you to run images that are not available for the ARM64 architecture.
services: db: platform: linux/x86_64 image: mysql:5.7 # Add your service configuration here
Solution 2: Using MariaDB as a Drop-in Replacement
Since MariaDB offers ARM64 support and can serve as a drop-in replacement for MySQL, you can use it instead. Here’s how you can configure it in your docker-compose.yml
:
services: db: image: mariadb:10.5.8 # Add your service configuration here
MariaDB is fully compatible with MySQL, offering the same commands, interfaces, libraries, and APIs.
Solution 3: Using Official MySQL ARM64 Image
Oracle maintains MySQL images compatible with ARM64, which can be used directly. To use the official MySQL ARM64 image, you can specify it in your docker-compose.yml
:
version: "3.8" services: mysql: container_name: mycontainername image: mysql/mysql-server:8.0.23 ports: - "3306:3306" environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: mydatabasename MYSQL_ROOT_HOST: "%" command: --lower_case_table_names=1
Solution 4: Using Platform Emulation
If none of the above solutions suit your needs, you can force Docker to emulate the x86_64
platform. This is achieved by adding a platform specification in your docker-compose.yml
:
services: mysql: image: mysql:5.7 platform: linux/amd64 # Add your service configuration here
Conclusion
Running MySQL on Apple Silicon (M1) using Docker requires specific considerations due to architecture compatibility issues. By specifying the platform for emulation, using MariaDB as a replacement, or opting for the official MySQL ARM64 image, you can overcome these challenges. Keep in mind that using emulation might impact performance, so it’s often better to use ARM64 compatible images when available.