Docker for DevOps: Basics
Hey Folk! From today we will focus on advanced concepts in the journey towards DevOps.
What is Docker?
Docker is a software platform that allows building, testing, and deploying applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.
Why we use Docker?
Docker has multiple use cases. Following are some of them
- Faster software shipping
- Standardizing operations
- For Seamless Migrations
- Cost Effective
When we use Docker?
Following are some of the events where docker’s helpful.
- Handling Microservices
- Continuous Integration and Delivery
- Data Processing
- Container as a Service
Now we will see some of the important commands in docker.
For that, I have installed it on my Ubuntu VM on my local computer.
Guide to install docker on Ubuntu VM
First I will check if my docker service is running or not.
sudo systemctl status docker
This will show me the current status of the docker
As it is running, I will simply run the following command to run docker.
Now we have verified the docker installation as well. The hello-world in docker is always stored as a docker image.
To list all the docker images
docker images
Now to list the contents of a docker image we use the following command
docker inspect [image-name]
#or
docker inspect [image-id]
Both these commands list all the contents of the docker image
To list the port mappings for a container, we use the following command
docker port [container-id/container-name]
Now to check for stats, how many resources are being used by any of the containers that are running? For that, we use the following command
docker stats
This lists the container and the usage.
If to display the running processes inside the container, we use the following docker command.
docker top
If we want to zip a particular image in .tar format, we use the following docker command.
docker save -o filename.tar image_name:version
#we can give multiple images as well
docker save -o filename.tar image_name:version image2_name:version
#or we can use the following command
docker save image_name:version > filename.tar
This created a zip of Nginx's latest image
Now to extract an image from a zip file we use the following command
docker load -i filename.tar
This loads the zipped image
So these were some basic docker commands everyone must know.
Previously we installed docker on Ubuntu VM on the local system, now we will install it in the AWS EC2 machine.
First, we will start an EC2 machine. Head over to your EC2 Instance Dashboard. Click on Launch Instance. Give it a good name and then select Ubuntu from the OS and the free-tier eligible service
After selecting the storage type that is free tier eligible and your key pair(you can create one as well) to connect SSH
After configuring the network security settings under the security group section, you can create one and select from the existing one as well. After this in the User data under the advanced tab write the following commands.
#!/bin/bash
# Update package list
sudo apt update
# Install OpenSSH server package
sudo apt install -y openssh-server
# Start SSH service
sudo systemctl start ssh
# Enable SSH service to start on boot
sudo systemctl enable ssh
This will install an SSH Server when launching the instance.
After that press on Launch Instance. Congratulations, you have launched an EC2 instance
After some time the instance will be launched. To connect it using SSH, open the cmd in a location where you have stored your key-value-pair key.
After launching the instance when it comes in the running state, connect to the instance. You can use the SSH to connect or directly is the browser as well. It takes some time to install and configure the SSH server.
Copy the ssh command from the connect section and paste it in the cmd in the directory where the key-pair is stored.
As now I am in my Ubuntu Matchine. I will run the following commands to install Docker.
#Updating the already present packages
sudo apt update
#Installing docker
sudo apt install docker.io
#Checking status of Docker
sudo systemctl status docker
#If docker does not start automatically
sudo systemctl start docker
This is how we can install Docker.
This was all from today, we will see how to make containers and run them later on.
Thank you for giving it a read.