Question about Docker and MySQL

iosoft

PC enthusiast since MS DOS 5
Skilled
Friends,

This is the 1st time I am setting up a dedicated server at my home using RPi 4 (with Static IP).
I am also installing Docker to host and manage few sites and WordPress installations.
(mostly my previous works as demo which are no longer available in live sites)

I have a little doubt regarding Docker and MySQL, how to setup?
I do not want that every container uses its own MySQL instance which will take up too much memory and space of my RPi 4.
I want to run single common MySQL instance.

  • Option 1: Run MySQL as a dedicated Docker Container?
    But, I might need MySQL access from outside Docker, like some Linux scripts, some database mirroring etc.
  • Option 2: Install and run MySQL as local (traditional Linux installation)
    Will it be easy to access this MySQL by the Docker Containers?

Pls suggest.
 
  • Option 1: Run MySQL as a dedicated Docker Container?
    But, I might need MySQL access from outside Docker, like some Linux scripts, some database mirroring etc.
  • Option 2: Install and run MySQL as local (traditional Linux installation)
    Will it be easy to access this MySQL by the Docker Containers?

Running it on the docker is a very plug n play solution. It's just one line command. There's not even any performance penalty. And you can expose port used by the mysql container, this way you can access mysql from other containers or even from the host linux.

Installing any db on the host system creates a mess. Even before docker was a thing, I used to install all my dbs in virtual machines.
 
Installing any db on the host system creates a mess. Even before docker was a thing, I used to install all my dbs in virtual machines.
Actually I am expert in installing DBs in direct host PC :p
Thank you for your suggestion.
 
  • Option 1: Run MySQL as a dedicated Docker Container?
    But, I might need MySQL access from outside Docker, like some Linux scripts, some database mirroring etc.
  • Option 2: Install and run MySQL as local (traditional Linux installation)
    Will it be easy to access this MySQL by the Docker Containers?

Both should be functionally identical. The docker image is a lot easier to install and maintain since it's self-contained, while the traditional installation will be easier to get working with all your other stuff. I would personally go for the docker route, but there's three things you have to keep in mind:
  1. Other containers will not have access to the MySQL container unless they're on the same docker network, and since (AFAIK) a container can't be part of more than one network at a time, this means that all your containers that need MySQL will have to be on the same network. This isn't necessarily a bad thing, but it means that you won't be able to have separate networks for different groups of containers.
  2. You won't be able to blindly follow the install guide for most things - you'll have to modify the docker command/compose file to account for your changes. This can be a little confusing at first, but once you get the hang of how the docker networks work it won't be too difficult.
  3. As @lockhrt999 said, you'll have to be careful to manage your container volumes/bind mounts properly.
That said, if you're experienced with bare metal DB maintenance, you may as well do that.
 
I think what you are looking for is the " -p " option when running the docker mysql container to expose/forward the port 3306 so that other containers can access it within your rpi4?
Another thing to keep in mind that storage of the container is ephemeral. You will want to save actual database file of the mysql on the host OS.

This I believe can be handles with the " -v " option to mount local path as volume mount in the mysql docker container?
 
Back
Top