M1 Mac Docker Issue — MySQL

therealbryanho
2 min readJun 28, 2021

At the time of writing this article, setting up a WordPress container was a pain. If you found this article, you probably know what I mean.

Here’s the docker compose file that eventually worked to setup a WordPress container and works with M1 Mac.

Steps to setup WordPress container in Docker (Works even for M1 Mac)

Create docker-compose.yml

Use the below settings

version: '3'services:db:image: mariadbvolumes:- db_data:/var/lib/mysqlrestart: alwaysenvironment:MYSQL_ROOT_PASSWORD: somewordpressMYSQL_DATABASE: wordpressMYSQL_USER: wordpressMYSQL_PASSWORD: wordpresswordpress:depends_on:- dbimage: wordpress:latestports:- "8000:80"restart: alwaysenvironment:WORDPRESS_DB_HOST: db:3306WORDPRESS_DB_USER: wordpressWORDPRESS_DB_PASSWORD: wordpressvolumes:db_data:

Go to folder where your docker-compose.yml file resides

Run below command in Terminal

docker-compose up -d

Voila! Load up localhost:8000 and there you have WordPress working on Docker.

If you have been trying as many times as I have, you would already know that the issue was with mysql. In this case, though it is already working, it seems that there may be some poor performance due to amd64 emulation.

Mounting the container folder was my next challenge. After many tests with code from official Docker sources, Stack Overflow, and miscellaneous outdated blogs, I finally found what I needed with the Remote Development extension for Visual Studio Code.

How to Edit Files and Develop inside Docker?

If you’ve got no time to bother with volumes and mounting, here’s the easiest way to do it. Run through the comprehensive Visual Studio Code guide for Developing inside a Docker Container https://code.visualstudio.com/docs/remote/containers

Bonus: Install Nodejs in your Docker Container

Took me a few tries to find the formula. If you have successfully connected to your container, access Terminal and go through the following commands to install Nodejs to your Docker container.

# update 
apt-get update
# install curl
apt-get install curl
# get install script and pass it to execute:
curl -sL https://deb.nodesource.com/setup_14.x | bash
# and install node
apt-get install nodejs
# confirm that it was successful
node -v
# npm installs automatically
npm -v

Use curl -sL https://deb.nodesource.com/setup_14.x | bash for node 14.x

Replace 14 by your desired node version e.g. 12, 16, etc.

If you need to use Git, here’s the command to install it from Terminal.

apt install git-all

In Summary…

Hope this has helped. I still foresee upcoming challenges in using a M1 Mac for development, and I’ll update this article along the way. But hopefully not.

Leave a tip: https://therealbryanho.gumroad.com/l/mepuo

--

--