Docker Administration
1.1 Introduction to Docker
1.2 Prerequisites — Hands-on Lab
1.3 Docker Installation — Hands-on Lab
2.1 Installation and configuration of docker — Hands-on Lab
2.2 Installation Issues — Q&A
3.1 Docker Commands — Hands-on
3.2 Container Creation and Administration
4.1 Image Creation and Administration
4.2 push/pull docker images in private and public repository Hub
5.1 DevOps Pipeline and Administration
5.2 Docker demerits
1.1 Introduction to Docker
In the fast-paced world of software development, efficiency and consistency are key. Docker, a revolutionary platform for containerization, has become an essential tool for developers and DevOps engineers. This guide will introduce you to Docker, explain its core components, and show you how to get started. Let’s explore how Docker can streamline your development process and improve deployment workflows.
What is Docker?
Docker is an open-source platform that automates the deployment of applications inside lightweight, portable containers. These containers package all the dependencies an application needs, ensuring it runs consistently across different environments, from development to production.
Why Use Docker?
Docker offers several significant advantages that have made it popular in the software development community:
- Portability: Docker containers can run on any system that supports Docker, whether it’s a developer’s laptop, a data center, or the cloud.
- Efficiency: Containers are lightweight and share the host operating system’s kernel, making them faster and more resource-efficient than traditional virtual machines.
- Consistency: Docker eliminates the “works on my machine” problem by providing identical environments across different stages of development and deployment.
- Scalability: Easily scale applications up or down by deploying multiple containers. Docker integrates well with orchestration tools like Kubernetes and Docker Swarm for managing complex deployments.
Key Components of Docker
To understand Docker, it’s important to familiarize yourself with its core components:
Docker Images
A Docker image is a read-only template that contains the application’s code, runtime, libraries, and settings. Think of it as a blueprint for creating Docker containers.
Docker Containers
Containers are instances of Docker images that run applications. They are isolated environments that encapsulate everything needed to run an application, including the system libraries and settings.
Dockerfile
A Dockerfile is a script with a series of commands and instructions on how to build a Docker image. It automates the image creation process, ensuring consistency and reproducibility.
Docker Hub
Docker Hub is a cloud-based registry service where you can find and share Docker images. It hosts a vast library of pre-built images, making it easier to get started with Docker.
1.2 Lab — Prerequisites
- Google cloud Account with working condition — even trial account also fine
Day 1 Installation of Docker in GCP:-
We are going to install Docker on the google Cloud platform free account. Please create a account which google initially provides the 300 credits to use the environment.
Click on the Vm instances and please create the VM with the below configuration
Inputs to be Provided
- Name : Docker1
- Region,Zone,
- Machine configuration :
- Machine type : Custom Cores -4 vcpu,Memory 4GB
- Boot Disk : Follow the below
- Identify and APi Access
Installing Docker
Commands to install docker
Docker Installation in UBUNTU
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
sudo systemctl start docker
sudo systemctl enable docker
sudo gpasswd -a rangarajbk_db docker
Please restart the Vm after this for the changes to take effect
Command to check the docker information
docker info
command to check the docker version
docker --version
3.1 How to identify official images from docker hub
Command to check the httpd image available from the repository
docker search httpd
Command to install httpd image from the repository to local
docker run httpd
Command to login into the httpd image bash profile
docker run -it httpd bash
Command to check on the images. This command shows the running and exited images
docker ps -a
Command to run the docker nginx image on the background
docker run -dit nginx
to exit from the https image
Command to pull the httpd image
docker pull httpd
command to check all the images available in the docker
docker images
When using the httpd image an connect to the google it will not work
docker run httpd ping google.com
Command to install the busybox to connect to the google
docker run busybox ping google.com
Command to run the nginx in the foreground
docker container run --publish 80:80 nginx
Command to run the nginx in the background
docker container run --publish 80:80 --detach nginx
The local port is 80 ,The docker port is 80
--to check the images
docker images
Command to inspect a container
dcoker container inspect <Container_name>
command to run the docker image name
docker run -d --name server1 httpd
command to run the service httpd in your specific name rangarajbk_db
docker run -dit --name rangarajbk_db -p 8087:80 -v /var/tmp/:/usr/local/apache2/htdocs/ httpd:2.4
8080 port → base linux machine port
80 → docker image port
/var/tmp/ → base linux machine directory
/usr/local/apache2/htdocs/ → docker image directory →(goto docker hub and check it)
Steps to run the container and how to find out the IP address of the container
docker run -d --name nginxrangarajbk nginx
docker ps
docker exec -it nginxrangarajbk bash
echo “hi how are you” > /usr/share/nginx/html/index.html
Command to run the docker on the dynamic port selection
docker run -d -P --name web httpd
Tested the docker on the URL with the external ip and the port 32768
command to remove the stopped or exited docker
docker stop $(docker ps -q)
Command to remove all the docker container
docker rm $(docker ps -a -q)
Command to check the list the exited containers
docker ps -a -f status=exited
Command to remove exited and quit container
docker rm $(docker ps -a -f status=exited -f status=created -q)
Command to check the history of the images
docker history <image_id>
Docker Images
command to login into the registry and repository. It will ask for tthe username and password. Please provide
docker login
Command to search the httpd image in the repository
docker search httpd
Command to pull the image from the repository
docker image pull httpd
command to push an image
docker image push httpd
Command to check the list of images
docker image ls
Command to check the history of the Docker image
docker image httpd
Command to inspect the image
dcoker image inspect nginx
3.2 Create Containers and manage them
Command to publish the publish webserver ngnix in port 80
docker container run --publish 80:80 --detach nginx
Command to inspect the docker container
docker container inspect 050dfb3a4cf8
command to remove all exited or stop containers
docker system prune
Command to restart the specific container
docker restart <container_id>
Command to stop a container
docker stop <container_id>
command to kill a docker container
docker kill <container_id>
Command in docker lists the details of all the network in the cluster
docker network ls
4.2 Create a docker hub login with email and password
Create a public repository name dev
Create the below file from the docker
vim dockerfile
FROM rockylinux/rockylinux
MAINTAINER Devops Engineer
RUN yum update -y && yum -y install httpd
Save the file and run the below command
docker build -t rangarajbk/dev:v1.0 .
docker push rangarajbk/dev:v1.0
- rangarajbk is the username
- dev is the repository name
- version1 is the tag name
After the push command now you can see the image in the dev public repository
Try to create a new vm machine and install the docker. After that without performing the docker login try to pull the image and it should work as the image is in the public repository
Create a public repository name prod
Run the below command to build the images on the local docker
docker build -t rangarajbk/prod:version11 .
- rangarajbk is the docker username
- prod is the private repository name
- version 11 is the tag used
docker push rangarajbk/prod:version11
Check the image on the docker.hub under the prod private repository
The pushed image is available.
Perform the testing on the docker2 machine to pull the image in the private prod repository without using the docker login command
This error is expected and it should not work as its a private repository image.
If there is a need for the private repository usage the role based access should be enabled in the docker.hub under the respective repositories