Yeah, I wanted to do one of those for a long time 😁
So, we have to stay at home for the moment, I decided to make a “walkthrough” about something I used sometimes and I couldn’t remember all the commands. So, let’s build our MySQL database within a Docker container 🐳 !
Get the Docker image
I will be using the
mysql image from the Docker hub.
Run the container
For further details, you can read the official documentation for the image on Docker hub. I will just go through the basic steps I use.
--name: setup a name for our container
-e: setup environment variables
MYSQL_ROOT_PASSWORD: need explainations ?
-d: run in deamon mode
mysql:latest: use the
mysqlimage in the latest version
Administrate the database
Once the container is running in background, we have to connect to it :
Here, we connect to the running container and pop a shell in interactive mode. We have to connect to the database :
Now we can start to use SQL commands for our database.
Create the database
Create the table
Manipulate the table
We want now to add some data in our table :
Oh no, I f’cked up my data ! Apple & banana is not that tasty !
So drunk I added apple & apple in my table sight
OK, we are good.
I want to see my beautiful compotes now !
Use SQL script
We don’t want to re-type all the database when building a new container !
SQL scripts are cool for that :
And execute the script on the running container :