Published: 2 January 2021
Docker enables us to separate applications from infrastructure so that we can deliver applications quickly. Today, docker is one of the standards to build and share containerized applications .
Docker helps developers recreate exact copy of development and production environments. Though running a database instance in docker comes with other challenges, this post shows how quick it is to run a mysql database instance using docker compose for development purposes.
This example below is tested on windows 10 with docker desktop version 3.0.0 running on WSL2.
version: "3.4"
services:
mysqldb:
image: mysql:8.0.20
restart: always
environment:
MYSQL_ROOT_PASSWORD: strongpassword!
MYSQL_USER: usermysql
MYSQL_PASSWORD: strongdbpassword!
MYSQL_DATABASE: customerdb
ports:
# host : container
- "33061:3306"
Let us go through what each line does in docker-compose.yml
version: "3.4"
services:
mysqldb:
image: mysql:8.0.20
restart: always
environment:
MYSQL_ROOT_PASSWORD: strongpassword!
MYSQL_USER: usermysql
MYSQL_PASSWORD: strongdbpassword!
MYSQL_DATABASE: customerdb
ports: -'33061:3306'
Open the windows terminal /powershell and in the repository where we had saved the docker-compose.yml file execute the following command.
docker-compose up
We have seen a mysql instance running as as docker image using compose file. To move this in production learn more about volumes for data persistence .