
Database setup with podman/ Docker containers
A quick start guide for starting your journey with database alongside a bit of containers, especially for Linux guys! Please refer to the table of contents for jumping to the part you need!
My SQL
MySQL is a RDBMS software which use SQL like syntax to manage databases. Nowadays most of the major Linux distributions come with maria db preinstalled, which is an open source drop in replacement for MySQL. I’ll be writing about some ways to install MySQL in linux based operating systems,
Container Installation
One another good way to install MySQL is to use a podman or docker container. I personally prefer podman so I will be writing about it. Installing a container running only MySQL is pretty much easy. We just have to grub the image and run it in a container. It’s volume will be created automatically. Or if we also want to include a phpmyadmin web app to manage our image then we actually have to use a pod to contain two different containers.
Setup a container
Whatever, let’s install podman! You can follow the official documentation for this. I guess most of the major linux distributions have podman in their official repositories.
Like, for Arch Linux:
|
|
MySQL image
To setting up MySQL image, we can pull it from dockerhub. The command will be like,
|
|
As an alternative you can also use mariadb image.
Then, we can start and run our image with the following command,
|
|
Here our root password is defined as tree by the environement variable MYSQL_ROOT_PASSWORD
.
And if we try to do list running process we can execute,
|
|
It will see our image up and running. Now let’s actually enter to our server!
|
|
Let’s run a command to verify,
|
|
It’ll list all databases.
Now with localhost:3306
you can access this database from mysql workbench or other clients.
Phpmyadmin image [OPTIONAL]
Phpmyadmin is a web UI for managing MySQL databases. Let’s pull it first,
|
|
Now if run this image we won’t be able to access another image (MySQL) because there’s no connection in between them. So we will be using podman pod. Let’s create a podman pod,
|
|
If we have previously created an image as per this guide and that is up and running, try the following command to stop and delete,
|
|
Now let’s start our mysql server under this pod,
|
|
And finally let’s open our phpmyadmin with this pod,
|
|
It will be availabe under port 8080, as like we defined earlier. So let’s head over to,
Here, our,
|
|
Hope you can figure out the rest! With the same approach as above, it’s easy to setup any database. But if your’e using
docker
, unlike me, then you may needkubernate
for creating pods. (Linking multiple containers).
XAMPP
Xampp is a popular tool which is an open source cross-platform web server solution stack package developed by Apache friends. It can be installed via the official website’s installer. Here a .run
file will be downloaded which can be installed by executing from a terminal. But it is not recommended to install in this way.
The most recommended way is to search for a similar package in distros native package manager. For example, in Arch Linux the package is available through AUR (Arch User Repository). Here’s the git-clone URL,
To install it, we can use a AUR wrapper like yay
. To do so, use the following command to query and install the latest version of xampp
.
|
|
After installing open the app, head over to the second tab and start database and web server. Web UI will be available under localhost:8080
.
XAMPP
may use maria-db instead of MySQL. But that should not be an issue, I guess.
Oracle Database
Intro
Mainly I will be focusing linux, but will work on mac as well, with some of it’s commands tweaked.
For windows? You can download the installer from the official website and follow the instructions.
Container Installation
Docker and podman are the two most popular containerization tools. I will be using podman for this, and I will recommend podman as well. Why? Maybe I will write a blog on this later.
Setup a container
Whatever, let’s install podman! You can follow the official documentation for this. I guess most of the major linux distributions have podman in their official repositories.
Like, for Arch Linux:
|
|
Pull the image
There are mainly two images available for free, full and lite.
To get the full image:
|
|
And to be honest, it’s a huge image around 9.48 G. So, I will recommend the lite version. It may take upto 2 G.
|
|
Run the container
Now let’s go ahead and actually run the container.
|
|
Here, I have used the lite version of the image. You can use the full version as well. Just replace the image name.
And the port 1521
is the default port for Oracle Database. You can change it if you want.
Flag
-d
is used to run the container in the background.
Flag
-p
is used to map the host port to the container port.
Flag
--name
is used to give a name to the container. (Try to remember it!)
Set a password
Here I have used 1234
as the password. You can use whatever you want.
|
|
Connect to the database
You can use any database client to connect to the database. I will be using SQL*Plus.
|
|
And then enter the following details:
- Username:
system
- Password:
1234
(Or the one you set in the previous step!)
Stop the container
|
|
Start the container
|
|
You may need to start the container if you have restarted your system!
Vscode integration
It would be weird if we have to use terminal everytime we want to access our database, right? Let’s use vscode. Simply install the following extension,
Or, Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
ext install Oracle.sql-developer
.The size of this extension is more than 300 M, so it’ll take a bit of time.
-
Now on our left/ right toolbar, you will find a icon, and maybe try to add a new connection? You will asked to fill up a form.
-
For the port number try to use the one you got from
podman port oracle-db
. -
For the username, use
system
. -
And for the password, use the one you set in the previous steps.
-
For the service name, it should be
FREE
. Or you can use the following code insqlplus
to get the service name,
|
|
And you are good to go!
SQL server
For Microsoft SQL Server, you can do the same with above steps. Official docs are available here. Let’s take a look,
- Docker: Install Containers for SQL Server on Linux - SQL Server | Microsoft Learn
- Deploy and Connect to SQL Server Linux Containers - SQL Server | Microsoft Learn
Container Installation
Setup a container
Whatever, let’s install podman! You can follow the official documentation for this. I guess most of the major linux distributions have podman in their official repositories.
Like, for Arch Linux:
|
|
Pull the image
SQL Server’s latest version may require podman with root. So lemme use an older version instead for now.
Let’s pull the image first,
|
|
Run the container
Let’s run it now,
|
|
Connect to the database
Finally connect with,
|
|
We may need to use
-C
flag to trust connection.
Here, if you want to work in the CLI, write your commands but you won’t see any output. For output use, GO
query. Like this one,
|
|
Vscode integration
In vscode, you can use the SQL Server (mssql) extension to easily get the GUI! Create a new database project and connect with,
|
|
Misc
Port address
To get your outgoing forwarded port from podman, use the following,
|
|
Listing all images
To list all of your podman images for space consumption, you can try,
|
|
Here’s an example output,
|
|