In this tutorial we will show how easy it is to play with databases using docker
Each verison of MySQL has a different tag or label in docker and these can be found here on Docker Hub
We will also demonstrate the use of Docker Compose see official docs here - https://docs.docker.com/compose/
you must first choose which version you want
docker pull mysql:5.7.30Notice we are create a spec that containes two separate docker containers that we want to talk to eachother on an internal private docker network. Notice we do not not need expose any ports on the database side only the database ui as the ui and database will talk on an internal network. If we want to access the database via jdbc we must expose the containers ports
version: '3.1'
services:
db:
image: mysql:5.7.30
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
- 3307:3306
environment:
MYSQL_ROOT_PASSWORD: Password1
MYSQL_DATABASE: mydatabase
MYSQL_USER: user1
MYSQL_PASSWORD: Password1
adminer:
image: adminer
restart: always
ports:
- 8080:8080
docker-compose up -d
docker psnavigate to http://localhost:8080/
The database name must match the name of the database service in the compose-file as this becomes like the dns name of the database IP address on the docker internal network
docker-compose down -d
docker ps