How to Run MySQL in a Docker Container on macOS with Persistent Local Data

Casey McMullen
5 min readDec 20, 2018

This article is an easy step-by-step guide to setup MySQL containers for your macOS development environment and have the data remain on your localhost between container starts, stops and builds.

Being able to run MySQL in Docker containers for your DEV environment is extremely handy. With just a few steps you can set up an environment that allows you to run multiple versions of MySQL if necessary, pick and choose the one you want to use, and keep the data on your localhost instead of inside the container — where it will disappear if you should stop, remove and rebuild your container instance.

This article will show you how to set up a container with MySQL 8.0 on macOS 10.14 Mojave, but these steps will work with MySQL 5.6 or 5.7 as well as all versions of macOS capable of running Docker Desktop for Mac.

< UPDATE: DEC 14, 2019 >

Originally, when I wrote this article, I instructed to create the folder /usr/local/opt/mysql/8.0 and this folder was used for persistent data storage.

Since then I’ve decided that storing the persistent data in a folder in your Mac /Users folder makes more sense. It eases the process of permissions handling and Docker already recognizes the /Users folder for file sharing by default so you…

--

--

Casey McMullen

Co-Founder & CEO at Another™ : Web Developer : Tech Geek : Guitar Player