Start working with mysql docker image and mysqldata folder on host machine.

Paul NGUYEN
1 min readJul 24, 2019

I don’t want to explain in detail what is docker compose file, but short description it is yml file describing how to start docker images

In the following example, I shows how to run mysql server with mysql data folder ( folder which stores data of your mysql server)

Inspiring example from Chris ( https://medium.com/@chrischuck35/how-to-create-a-mysql-instance-with-docker-compose-1598f3cc1bee) and romani ( https://rominirani.com/docker-on-windows-mounting-host-directories-d96f3f056a2c)

the final docker compose file is in C:\projects\docker\mysql2\docker-compose.yml :

version: '3.3'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: 'db'
# So you don't have to use root, but you can if you like
MYSQL_USER: 'user'
# You can use whatever password you like
MYSQL_PASSWORD: 'password'
# Password for root access
MYSQL_ROOT_PASSWORD: 'password'
ports:
# <Port exposed> : < MySQL Port running inside container>
- '3306:3306'
expose:
# Opens port 3306 on the container
- '3306'
# Where our data will be persisted
volumes:
- C:/server/docker/mysql/data:/var/lib/mysql

Go to DOS console in folder C:\projects\docker\mysql2

|C:\projects\docker\mysql2>docker-compose up

Now your server mysql is up and all data is saved in folder C:/server/docker/mysql/data.

--

--