Introduction of Docker
Docker is an open-source project that automates the deployment of Linux applications into virtualized containers. Docker provides a layer of abstraction and virtualization based on Linux. Docker uses isolated Linux resources such as cgroups, kernel, and file managers to allow containers to run independently within a Linux entity.
Changes are stored in Docker images, and the file system layers are created and saved on a layer-by-layer basis. This helps the Docker Image reduce significantly in size compared to the virtual host (VM).
Applications that want to run using Docker must be applications that can run on Linux. Docker has recently added support for running Windows applications in Windows containers.
Main components of Docker
- Docker Engine: used to create Docker images and run Docker containers.
- Docker Hub: a hosting service that holds Docker images.
- Docker Machine: creates Docker engines on the server.
- Docker Compose: run the application by defining the configuration of Docker containers through the configuration file.
- Docker image: a collection of application files generated by the Docker engine. The contents of Docker images will not be changed during migration. Docker images are used to run Docker containers.
- Docker container: a runtime form of Docker images used as a runtime environment for applications.
Implementation Guide
Step 1: Update the system
You proceed to update the packages installed on the Ubuntu system with the command:
sudo apt update -y && apt upgrade -y
Step 2: Install Docker
To install the latest Docker, you should install it directly from the Docker repository.
- Install some packages that allow HTTPS.
sudo apt install apt-transport-https ca-certificates curl software-properties-common
- Add the GPG key of the Docker repository.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- Next, add Ubuntu 22.04’s Docker repository (jammy) to apt sources.
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- Update packages and set to install Docker from official repositories.
sudo apt update sudo apt-cache policy docker-ce
- Install Docker
sudo apt install docker-ce -y
- Check Docker’s Status
sudo systemctl status docker
Step 3: Configure Sudo permissions for users using Docker
Docker requests are only executed as the root user by default. Therefore, if you use other users, you need to add that user to the Docker group to have the right to operate.
sudo usermod -aG docker username
Step 4: Use the Docker command
- View information about Docker
docker info
Introduction Docker Compose
Docker compose is a tool to define and run multi-containers for Docker applications. With compose, you use the YAML file to configure the services for your application. Then use the command to create and run from those configs. The steps to use are also quite simple, as follows:
- Declare the app’s environment in Dockerfile.
- Declare the services needed to run the application in the docker-compose.yml file.
- Run docker-compose up to start and run the app.
Prerequisites before installing Docker compose
- You must have SSH access
- The server must have Docker pre-installed.
Implementation Guide
Step 1: Install Docker Compose
- To install the latest version of Docker Compose from the GitHub repository, use the following command:
sudo curl -L https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
- Permissions for the downloaded file
sudo chmod +x /usr/local/bin/docker-compose
- Check results after installation
docker-compose --version
So Docker Compose has been successfully installed and you can start running containers.
Leave A Comment?