Outline
What do we mean by Docker?
How Docker works
Docker properties
Why use Docker
Some important terms in Docker
Install Docker on an Amazon Web Services (AWS) instance
Some basic commands for Docker
What do we mean by Docker?
Docker is an open-source platform used to build, run and manage applications inside containers. Where containers represent an isolated and lightweight environment that contains all the components needed to run a specific application, including source code, settings, libraries, tools, and the file system, and this makes them very similar to virtual machines (Virtual Machines), but they work more efficiently and quickly. Docker technology enables developers to uniformly develop and port applications between development, test, and production environments, reducing compatibility and dependency issues on specific environments. Developers can define the architecture of their applications using configuration files that define the required environment and settings, and then use Docker to create containers based on these definitions.
And it downloads to your operating system, be it Windows, Linux, Mac, or any other operating system
So, Docker is a tool through which containers are controlled.
How Docker works
Docker works by providing a standard way to run your code. Docker is an operating system for containers. Similar to how a virtual machine virtualizes (removes the need to directly manage) server hardware, containers virtualize the operating system of a server. Docker is installed on each server and provides simple commands you can use to build, start, or stop containers.
AWS services such as AWS Fargate, Amazon ECS, Amazon EKS, and AWS Batch make it easy to run and manage Docker containers at scale.
Docker properties
Each application that runs in the container will work in isolation from other applications in the rest of the containers, as it will be as if each application is running on an operating system alone, but the truth is that it is one operating system and all applications in the containers share it, and the Docker engine is the one that performs the management currency.
More than one container can run on a single operating system and is run by the Docker engine.
Applications can be run on Docker through containers on a private laptop, on a server, or on the cloud.
Why use Docker
Using Docker lets you ship code faster, standardize application operations, seamlessly move code, and save money by improving resource utilization. With Docker, you get a single object that can reliably run anywhere. Docker's simple and straightforward syntax gives you full control. Wide adoption means there's a robust ecosystem of tools and off-the-shelf applications that are ready to use with Docker.
- Ship more software faster
Docker users on average ship software 7x more frequently than non-Docker users. Docker enables you to ship isolated services as often as needed.
- Standardize Operations
Small containerized applications make it easy to deploy, identify issues, and roll back for remediation.
- Seamlessly move
Docker-based applications can be seamlessly moved from local development machines to production deployments on AWS.
- Save money
Docker containers make it easier to run more code on each server, improving your utilization and saving you money.
Some important terms in Docker
Image:
It is a template of code that cannot be modified. It is manufactured by other people or companies, such as Odoo, sonarqube, Ubuntu, Nginx, and others. It contains some instructions on how to create a Docker container through it.
The Docker image is all the things you need to run the application and it is light and small in size and easy to use because it contains only what the application needs.
Docker container:
It is a piece of software, such as icons, files, etc., that you need to run your application, and a container is an image that runs.
Registry:
It is a repository or registry that contains all Docker images The Docker Hub (https://hub.docker.com/) is a repository for all images created and supported by Docker and is available for anyone to use.
Client:
It is the primary means by which a user can interact with Docker to run commands, for example, pull, build, run, and others.
Which is a graphical interface, CLI, or something else, Docker uses an API to execute instructions or commands.
Docker demand:
It is a listener that waits for the command to be executed
If the image is on your local device, it creates a container from it, and more than one container can be run from the same image
If the image is not present, he will go to the registry ( Docker Hub ) and pull it from there.
Namespace:
Docker uses a technology called namespaces to provide the isolated workspace called the container, when you run a container, Docker creates a set of Namespace for that container. These Namespace provide a layer of isolation. Each aspect of a container runs in a separate namespace and its access is limited to that namespace.
Docker tag:
It is the address or reference to the docker image
More than one tag can refer to the same image. Docker images can contain multiple tags pointing to the layers of the same image, allowing you to easily
manage versions and references. Each image has a tag, so when the image is pulled without any tag, it pulls the latest. When specifying the tag, it removes the delimiter from it, for example, redis:alpain.
Image layers
Any change that happens or is made to the image is called a layer, which means that every command you specify (from, RUN, COPY, etc.) is a layer, and the sum of all layers is called a Dockerfile.
Dockerfile:
Is a text document that contains all the commands a user could call on the command line to assemble an image.
Dockerfile can build images automatically by reading the instructions from a Dockerfile.
Install Docker on an Amazon Web Services (AWS) instance
To install Docker on an Amazon Web Services (AWS) instance, you can follow these steps: Log in to the AWS Control Panel:
-Start logging in to your AWS account through the Control Panel (AWS Management Console).
Create an EC2 instance:
- Go to the EC2 section of the Control Panel.
- Click on "Launch Instances" to start the EC2 instance creation.
Name and Tags, AMI selections:
-Give the instance a name.
-Choose Ubuntu (free tier eligible) or another operating system that supports Docker as the instance platform.
Installation configuration:
- Choose the instance type (t2.micro-free tier eligible) or another type, and specify the required resources (such as processor type and memory size).
- Choose your SSH key (key pair) if this was done previously, or create a new key and save it somewhere safe.
- Follow the required steps until you reach the "Configure Security Group" section. In this section, make sure to configure Allow SSH port (port 22) to access the instance.
Instance launch:
- Browse and confirm the settings, then click "Launch instance". Accessing the instance via SSH:
Successfully launch the instance is done, click on the instance ID.
Connect to the instance:
After you launch the instance, you can use your SSH key to connect to it.
First, choose the instance and the click on connect `
-In the terminal window, Use the following command:
-chmod 400 teste.pem
Then:
-ssh -i "teste.pem" ubuntu@ec2-3-110-86-76.ap-south-1.compute.amazonaws.com
Execute the command:
Sudo –i
"sudo": is short for "Super User Do", which is a command that allows regular users to execute certain commands with root user privileges.
Docker installation:
After connecting to the instance via SSH and obtaining the root privilege, use the following command automation to install Docker:
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 && apt-cache policy docker-ce
Docker experience: Run a simple test command docker -v
to check that Docker is working properly and to see the Docker version:
Some basic commands for Docker
docker pull [image name]:tag
The docker pull command is used to download Docker images from a specified repository, where:
- Image name: The name of the Docker image you want to pull.
- tag: Optional tag (version) of the image. If not specified, it defaults to (latest).
For example:
This command will fetch the latest version of the Ubuntu image from the Docker Hub repository and store it on your local machine.
docker images
This command displays a list of all the images on your device with details such as the image's name, tag, and size.
docker rmi [image name:tag]
To remove one image. For example:
And again to display the images after removing by the command docker images
docker run [image name]
The docker run command is used to create and start a new Docker container based on a specified image. It allows you to run a command or process inside the container, and you can customize various aspects of the container's behavior using options.
For example:
To displays existing containers by the command:
docker ps –all
All containers can be shown even if there is more than one container for the same image by command: docker container ls –a
docker ps –a
To list all containers, including both running and stopped containers.
docker rm [container id]
To remove one or more container
Again, run the docker ps -a
command to show that the container is not in the list and that it has been deleted:
You can also specify a custom command to run in the container:
In this case, the echo "Hello, Docker!"
the command will be executed inside a new container based on the image.
The execution is Hello, Docker!
The docker run
command can be customized using various options to control aspects such as networking, volumes, environment variables, ports, and more.
docker container –d [image]
The -d
helps run the container in the background That is, when the screen is turned off by running the image and we open a new window, it remains present.
docker inspect [image]
The docker inspect command is used to obtain detailed information about a Docker container or image, including metadata, configuration, networking details, and more. It provides a comprehensive JSON-formatted output that can be useful for debugging, troubleshooting, or extracting specific information from Docker objects.
For example:
docker stats [container id ]
The docker stats
command is used to display a live stream of resource usage statistics for running containers. It provides real-time information about the CPU, memory, network I/O, and block I/O usage of each container. This command can be useful for monitoring and understanding the resource consumption of your Docker containers.
For example:
docker --help
Running docker --help
in the command line will provide you with a summary of the available Docker commands and their descriptions. However, the output might be quite extensive. Here's a simplified version of the output you might see:
and other commands ….
References:
Top comments (0)