Basics Of Docker ๐Ÿšข

ยท

5 min read

Basics Of  Docker ๐Ÿšข

Introduction

๐Ÿšข Welcome to the exciting world of Docker! If you've ever wondered how to package, ship, and run applications seamlessly, Docker is your magic wand. ๐Ÿณ

๐Ÿณ Docker is a powerful tool that simplifies the process of developing, shipping, and running applications in a consistent and efficient manner.

๐Ÿš€ Whether you're a developer, system administrator, or just curious about containerization, this blog will demystify Docker and help you grasp its core concepts and benefits.

Join me on this journey to uncover the magic of containers and revolutionize the way you manage your software deployments. ๐ŸŒŸ๐Ÿ‘ฉโ€๐Ÿ’ป๐ŸŒ

๐ŸŽญWe will learn by performing tasks

  1. Check version of docker

Install Docker on Ubuntu & check version

sudo apt install docker.io -y
docker version

Use the docker run command to start a new container and interact with it through the command line. [Hint: docker run hello-world]

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

OPTIONS: Various options to configure the container, such as specifying ports, volumes, environment variables, etc.

IMAGE: The Docker image you want to run the container from.

COMMAND: (Optional) The command to run inside the container.

ARG... : (Optional) Arguments passed to the command.

Example 1 :

docker run hello-world

above automatically downloads image by pulling from DockerHub.

Example 2 :

To run an instance of the official "nginx" web server image, you would execute.

docker run -d -p 80:80 nginx

If you want to keep the container running interactively, you can use the -it option.

docker run -it ubuntu /bin/bash

docker ps -a

  1. Use the docker inspect command to view detailed information about a container or image.
docker inspect [OPTIONS] NAME|ID [NAME|ID...]
  • OPTIONS: Additional options to format or filter the output.

  • NAME|ID: The name or ID of the Docker object you want to inspect.

Example :

docker inspect hello-world

  1. Use the docker port command to list the port mappings for a container.
docker port CONTAINER [PORT/PROTOCOL]

CONTAINER: The name or ID of the container you want to inspect.

PORT/PROTO: (Optional) The specific port and protocol (TCP or UDP) you want to inspect. If not specified, the command displays all port mappings for the container.

Example :

Create a container :

docker run --name mynginx -d -p 80:80 mynginx

docker port mynginx

  1. Use the docker stats command to view resource usage statistics for one or more containers.
docker stats [OPTIONS] [CONTAINER...]
  • OPTIONS: Additional options that you can use with the docker stats command. Some common options include --no-stream (displays only a single output) and --format (specifies a custom format for the output).

  • CONTAINER...: One or more container names or IDs. If no container names or IDs are provided, the command will display statistics for all running containers.

When you run the docker stats command, it continuously updates and displays a table with statistics for each specified container.

The table includes columns for the container's name, CPU usage, memory usage, memory limit, network I/O, and block I/O.

Example:

docker stats mynginx

  1. Use the docker top command to view the processes running inside a container.
docker top <container_name_or_id> [OPTIONS]
  • <container_name_or_id>: The name or ID of the container you want to inspect.

  • OPTIONS: Additional options that you can use with the docker top command. One common option is --pid which specifies the process ID to display processes for. By default, the command displays processes for all running processes in the container.

Example:

docker top mynginx

This command provides a list of the active processes running inside the container along with information about each process, such as its process ID (PID), user, CPU usage, memory usage, and command.

  1. Use the docker save command to save an image to a tar archive.
docker save [OPTIONS] IMAGE [IMAGE...]
  • OPTIONS: Additional options that you can use with the docker save command. One common option is -o or --output to specify the output file name.

  • IMAGE [IMAGE...]: The name or ID of the Docker image(s) you want to save. You can specify one or more images.

Example:

docker save -o nginx_image.tar nginx

This command creates a tar archive file called "nginx_image.tar" containing the "nginx" image.

7)Use the docker load command to load an image from a tar archive.

docker load [OPTIONS]  my_image.tar

OPTIONS: Additional options that you can use with the docker load command.

Example:

docker load -i nginx_image.tar

The docker load command reads the contents of the specified tar archive file from the standard input and imports the images contained in the archive into your local Docker image repository.

In short, Docker commands are like the Swiss Army knife for handling containers and images in Docker. They help you create, deploy, and control applications in their own little spaces. With these commands, you can do things like making images from Docker files, running containers, handling networks, and looking at container logs.

Mastering these commands makes life easier for DevOps Engineer, Developers and Admins, making work smoother, teamwork better, and applications more dependable in different situations

I hope you enjoy the blog post!

If you do, please show your support by giving it a like โค, leaving a comment ๐Ÿ’ฌ, and spreading the word ๐Ÿ“ข to your friends and colleagues ๐Ÿ˜Š

Did you find this article valuable?

Support Vyankateshwar Taikar's blog by becoming a sponsor. Any amount is appreciated!