Day 16 Task: Docker for DevOps Engineers.

Day 16 Task: Docker for DevOps Engineers.

Docker

Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.

Tasks🎈

As you have already installed Docker in previous days' tasks, now is the time to run Docker commands.

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

The docker run command in Docker is used to create and start a new container based on a specified image. It's one of the most fundamental and commonly used Docker commands, allowing you to launch isolated environments (containers) that run applications with their own file systems, networking, and other resources.

Here's the basic syntax of the docker run command:

docker run [options] <image_name> [command] [arguments]
  • [options]: These are various optional flags you can use to configure the behavior of the container.

  • <image_name>: Replace this with the name of the Docker image you want to create a container from.

  • [command] [arguments]: This part is optional. You can specify a command to run within the container and any arguments for that command.

Example:-

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

The docker inspect command in Docker is used to retrieve detailed information about Docker objects such as containers, images, networks, and volumes. It provides a comprehensive JSON representation of the specified object, which can include configuration, networking details, mounts, labels, environment variables, and more. This command is very useful for troubleshooting, understanding the setup of containers, and gathering information about Docker resources.

Here's how you can use the docker inspect command:

docker inspect <object_name_or_id>
  • <object_name_or_id>: Replace this with the name or ID of the Docker object you want to inspect.

Example:-

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

In the context of Docker, the docker port command is used to display the public-facing port of a container. It helps you see which ports from inside the container are being mapped to the ports on your host machine. This is especially useful when you want to access services running inside a Docker container from your host system or other machines in the network.

Here's how you can use the docker port command:

docker port <container_name_or_id> <container_port>
  • <container_name_or_id>: Replace this with the name or ID of the running container you want to inspect.

  • <container_port>: Replace this with the port number that you're interested in, which is the port inside the container.

Example:-

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

The docker stats command in Docker is used to display a real-time stream of resource usage statistics for running containers. It provides information about CPU usage, memory usage, network I/O, and more for each active container. This command is useful for monitoring the resource consumption of your Docker containers and can help you identify potential performance issues or resource bottlenecks.

Here's how you can use the docker stats command:

docker stats [options] [container_name_or_id...]
  • [options]: These are various optional flags you can use to customize the output or behavior.

  • [container_name_or_id...]: You can provide a list of container names or IDs as arguments to monitor specific containers. If no containers are specified, statistics for all running containers will be displayed.

Example:-

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

The docker top command in Docker is used to display the running processes inside a container. It provides a snapshot of the currently running processes along with their details, such as the process ID (PID), user, CPU usage, memory usage, and command.

Here's the basic syntax of the docker top command:

docker top <container_name_or_id> [options]
  • <container_name_or_id>: Replace this with the name or ID of the running container you want to inspect.

  • [options]: These are optional flags you can use to customize the output.

Example:-

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

The docker save command in Docker is used to save one or more Docker images as a tarball archive. This archive can then be shared or transported to other systems, where it can be loaded using the docker load command to recreate the images. The docker save command is particularly useful when you need to move Docker images between different environments or when you want to distribute images without relying on a Docker registry.

Here's the basic syntax of the docker save command:

docker save [options] -o <output_file>.tar <image_name> [<image_name>...]
  • [options]: These are optional flags you can use to customize the output or behavior.

  • <output_file>.tar: Replace this with the desired name of the output tarball archive.

  • <image_name>: Replace this with the name(s) of the Docker image(s) you want to save.

Example:-

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

The docker load command in Docker is used to load Docker images from a tarball archive that was created using the docker save command. This command allows you to restore Docker images on another system or in a different environment by loading the image layers and metadata from the tarball.

Here's the basic syntax of the docker load command:

docker load [options] -i <input_file>.tar
  • [options]: These are optional flags you can use to customize the loading process.

  • <input_file>.tar: Replace this with the path to the tarball archive containing the saved Docker images.

These tasks involve simple operations that can be used to manage images and containers.


Happy Learning

Thanks For Reading! :)

-Sriparthu💝