Skip to main content

Command Palette

Search for a command to run...

#90daysofdevops | Day 16

Day 16 -> Docker for DevOps Engineers

Published
4 min read
#90daysofdevops | Day 16

Docker :-

Introduction :

  • Docker is a critical tool for DevOps engineers, streamlining application deployment and collaboration.

  • It packages apps and dependencies into portable containers, ensuring consistency across environments. Containers offer isolation, boosting security, and ease of scaling.

  • Docker fits seamlessly into CI/CD pipelines, aiding testing and deployment automation. It supports microservices and IaC, promoting efficient collaboration between teams.

  • Its resource efficiency allows for more containers on the same hardware, and quick rollbacks simplify issue resolution.

DevOps engineers should grasp Docker commands, Compose, Kubernetes, and container registries, along with security and monitoring practices.

Tasks :

Task 1:

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

  • 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 :

Example 2 :

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

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

Task 2:

Use the docker inspect command to view detailed information about a container or image.

  • OPTIONS: Additional options to format or filter the output.

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

Example :

Task 3:

Use the docker port command to list the port mappings for a container.


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 :

Task 4:

Use the docker stats command to view resource usage statistics for one or more containers.

  • 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:

Task 5:

Use the docker top command to view the processes running inside a container.

  • <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:

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.

Task 6:

Use the docker save command to save an image to a tar archive.


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:

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

Task 7:

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


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

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.

Happy Learning...🚀