Docker container with mariadb image to have isolated environment inside a server.
This is a guide on how I (a beginner) connected a Node.js API with a Docker MariaDB container.
It's important to say I worked with Ubuntu 19.10 for this project.
Install all:
To quickly install all requirements, create a install.sh
file and place it whatever you want. You can use any text editor, the important thing is place inside install.sh
all commands provided by installation page linked above. It should look like this, docker example:
apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Once you have copied all commands, open terminal at location you saved the script, then type bash install.sh
and it will automatically install everything.
Getting started:
Once you have all installed, you can clone repo or fresh start, just open a terminal in folder you have the project and type:
npm install
to install all dependencies.
Run mariadb/server image
sudo docker run -p 3306:3306 --name maria -e MARIADB_ROOT_PASSWORD=password mariadb/server:10.4
You have connected to docker container.
Managing mariadb without client installed
sudo docker exec -it maria bash
to execute terminal inside container.mysql -u root -p
to access database (have to enter same password of MARIADB_ROOT_PASSWORD=password
)That is pretty much all, only thing you have to do is insert more data to mariadb maybe with post route and form in a web page, but this is like a boilerplate example.
Name | Description |
---|---|
Docker | Container service |
Node.js | HTTP Server |
MariaDB | Database |
I was getting an error when trying to get the data, was an error like "Error establishing a database connection", doesn't remember exactly, but I solved that using this guide.