C3rd
docker
Posted: 14 May 2024, 19:18pm - Tuesday
I have been using docker lately. I have these legacy personal projects that I can't just abandon them. Still display in my portfolio. :) Then my new projects are now using Symfony 6.4 with MySQL 8.0. It is the time that I need both MySQL v5.7 and v8.x to run side-by-side in my server. Here's my docker-compose.yaml
version: '3.1'
services:
mysql8:
container_name: docker_mysql8
image: mysql:8.0
ports:
- 3313:3306
restart: always
environment:
MYSQL_USER: user
MYSQL_PASSWORD: xxx
MYSQL_ROOT_PASSWORD: xxx
MYSQL_ROOT_HOST: "%"
MYSQL_PORT: 3306
volumes:
- /var/lib/mysqld8:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
timeout: 20s
retries: 10
networks:
- default
mysql5_7:
container_name: docker_mysql5_7
image: mysql:5.7
ports:
- 3312:3306
restart: always
environment:
MYSQL_USER: user
MYSQL_PASSWORD: xxxx
MYSQL_ROOT_PASSWORD: xxxx
MYSQL_ROOT_HOST: "%"
MYSQL_PORT: 3306
volumes:
- /var/lib/mysqld57:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
timeout: 20s
retries: 10
networks:
- default
then save it let's say at "/srv/mysql/docker-compose.yaml" and to initialise, run "docker-compose up -d"
one thing to remember though, if you want to make some changes. Never cast the command: "docker-composer down" because this will delete the data you got in the container unless you created backups.
instead, just do "docker-compose stop" to stop the container and "docker-compose start" when you want to get the container running again.
if errors encounter, simply just restart docker then cast "systemctl restart docker" then go to "/srv/mysql" and run "docker-compose up -d"