Docker Tutorial With Free Docker Lab in 2024

This Docker Tutorial is suitable for beginners to advanced levels. In this course, we are going to start from the basics of Docker fundamentals and gradually increase the level to Intermediate and advanced levels. You can also avail a Free Docker Lab to Practice Docker commands and concepts.

Docker Introduction: Docker Tutorial

Docker is a set of platform-as-a-service products that use OS-level virtualization to deliver software in packages called containers. The service has both free and premium tiers. The software that hosts the containers is called Docker Engine. It was first released in 2013 and was developed by Docker, Inc.

Enrolling in Docker Lab

  1. You can add Docker Lab to the cart from here https://www.itpanther.com/product/docker-virtual-lab/
  2. Go to Cart and Checkout https://www.itpanther.com/cart/
  3. Apply the coupon code to get 100% Discount LearnDockerNT3BRE7P
  4. Wait for an email which contains Docker Server Details and a URL to connect to the Docker Server

Installing and Running Docker Services

Installing Docker on Linux

Let’s connect to the server using the URL that you received in the email. After a successful connection to the server, we can use below command to install Docker.

sudo yum install -y docker

Starting Docker Services

Now we have successfully installed Docker. The next step is to start Docker services. We can do that using the following command.

sudo systemctl start docker

Checking Docker Service Status

Let’s check the docker daemon status by running the following command:

sudo systemctl status docker

Adding a user in the Docker Group

As you can see, to run docker services, we are prefixing sudo. Let’s add our current user to the Docker Group, so we don’t need to prefix sudo each time we use using Docker daemon client.

sudo usermod -aG docker $USER
newgrp docker

Running Docker Containers

Pulling a Docker Image

We can pull the image using the docker pull command. Let’s pull nginx image using the following command:

docker pull nginx

List all the Docker Images

We can list all the docker images using docker images command.

docker images

Running Nginx Docker Container

docker run -d -p 80:80 --name my-web-server nginx

Checking Running Docker Containers

docker ps

Stopping a Docker Container

docker stop <container_name or container_id>

Starting a Stopped Docker Container

docker start

Removing Docker Containers

docker rm

Running Website on Nginx Docker Container

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Website</title>
</head>
<body>
    <header>
        <h1>Welcome to My Website</h1>
    </header>
    <div>
        <p>This is a sample HTML website. You can replace this text with your own content.</p>
    </div>
</body>
</html>

Attach Local Storage to Docker Volume

docker run -d -p 80:80 -v /path/to/your/local/directory:/usr/share/nginx/html --name my-web-server nginx

Installing Redis Database on a Docker Container

docker pull redis
docker run -d --name my-redis-db -p 6379:6379 redis

Login to Docker Container

docker exec -it my-redis-db /bin/bash

Inserting Data to Redis

redis-cli
set course_name docker-demo
set objective mastering-docker-containers
set deadline mastering-in-3-days

Reading data from Redis

get course_name
get objective
get deadline

Restarting a Docker Container

docker container restart <container_name or container_id>

Removing a Docker Container

docker rm my-redis-db

Mount Volume to Redis Docker Container

docker run -d --name my-redis-db -p 6379:6379 -v $(pwd)/redis_data:/data redis

Understanding Docker Storage

Docker storage is basically two types of files:

  1. Container data: Data created and consumed by containers during execution time, such as documents, profiles, and databases.
  2. Image files: Files stored in the Docker image, including system files and metadata required to run the container.

Docker storage mode

Container storage

Container file system: Each container has its own independent file system, allowing it to store and transfer data independently of other containers.

Container Binding : A binding is a book or document that is placed inside the container, outside the container. They provide consistent storage and can be shared across multiple containers.

Image Storage

Image Layers: Docker images consist of multiple text-only layers stacked on top of each other. Each layer represents the transformation of data.

Image Registry: Images can be stored locally or in a remote repository (e.g. Docker Hub) called an image registry. The directory supports sharing and distribution of images across different media.

Key points in Docker storage

Copy-on-write (CoW)

Docker uses the concept of copy-on-write to optimize storage. When a container updates a file, Docker creates a new layer that only changes, leaving the old file unchanged. This minimizes storage overhead and speeds up container creation.

Volume

Docker volumes provide a way to save files created by containers. They can manage independently of the box, allowing data to be saved even if the box is removed. Containers can be placed in one or more containers to facilitate information sharing and collaboration.

Binding allows mapping a host or archive to a container file. Unlike the disk volume, the binding mount does not create new files but mounts the user manual directly to the box. A change in one direction will affect the other.

Storage Driver

The Docker storage driver is responsible for managing images and data containers on the host. Different drivers offer different levels of performance, stability, and compatibility. Drivers include overlay2, aufs, overlay and devicesmapper.

Best Practices

  1. Use disk volumes to store persistent data: Emphasize the use of disk volumes to store persistent data to ensure data integrity and portability.
  2. Improve image quality: Reduce image size and complexity to improve performance and reduce overhead.
  3. Backup and recovery: Regularly back up important files stored on Docker disk to prevent data loss and ensure disaster recovery.
  4. Choose drives carefully: Choose a storage drive based on your specific needs for performance, security, and compatibility.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top