Hi hope you are doing well, lets learn about “How to Setup and Install Docker on Linux and Run a MongoDB Container”, the Docker is the fastest growing technology in the IT market.
Many industries are moving towards docker from the normal EC2 instances. Docker is the container technology.
It is PAAS (Platform as a Service), which uses a OS virtualisation to deliver software in packages called containers.
The containers are the bundle of the packages, library files, and some configuration files. It was first started in 2013 and developed by Docker, Inc.
So lets have the Setup of Docker CE on Linux Step by Step Guide.
Setup and Install Docker CE on Linux
STEP 1: Update the Repository for the Docker to setup and Install on Linux.
So firstly we will update the repository and update the repo with the dnf command.
$ sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
So the above command will add the repo for Docker into linux.
$ sudo dnf update
dnf update command will update the repository, you might get the error while updating the repositories for dependencies or the conflicts error.
STEP 2: Setup and Install Docker CE on Linux via dnf command.
So, if the update was properly done then use “dnf install”, else use with the –allowerasing parameter.
$ sudo dnf install -y docker-ce docker-ce-cli containerd.io
If you will get the error while update then use below command
$ sudo dnf install docker-ce docker-ce-cli containerd.io --allowerasing -y
Once the docker installation get’s completed , start the services for the docker and enable it after rebooting the System.
$ sudo systemctl start docker.service
$ sudo systemctl status docker.service
So we have check the status for docker, and it is active running on the linux, so enable the service for docker at the time of booting.
$ sudo systemctl enable docker.service
STEP 3: Add the User in Docker Group.
Now lets add user “tastethelinux” into the docker group.
sudo usermod -aG docker $USER
“$USER” is the username tastethelinux, you can use whoami to check the username.
Docker version 20.10.8, build 3967b7d
So then check version using docker command without sudo, you will get the version for the docker.
So we have successfully install docker ce on Linux, lets create a Container for the MongoDB.
STEP 4: Test Docker by Pulling MongoDB Images.
So here we will create a container for MongoDB on docker, let’s use the pull command to pull the MongoDB image first.
$ docker pull mongo
So we have pulled the images for mongo from the docker, Once it’s completed you can check the image by using “docker images”.
$ docker images
STEP 5: Run MongoDB Docker Container in Linux.
Now let’s run the docker container by using docker run command.
$ docker run -d mongo
So we have successfully run the docker container in Linux for MongoDB, now if we have to verify the container is running or not use “docker ps” command.
$ docker ps
So we have install Docker CE in Linux, then run the container for MongoDB server on Linux.
Setup and Install Docker Compose on Linux.
Let’s install Docker Compose on Linux, with the curl command.
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
So, the above command will install docker compose in “/usr/local/bin” directory, now give the executable permission to the “docker-compose” script.
$ sudo chmod +x /usr/local/bin/docker-compose
Now lets create soft link for “docker-compose”, and check the docker compose version.
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
$ docker-compose –version
docker-compose version 1.29.2, build 5becea4c
So we have successfully installed docker compose on Linux, and also checked the version for docker compose command.