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
Use the
docker runcommand to start a new container and interact with it through the command line.The
docker runcommand is used to create and start a new Docker container from a specified image. It allows you to customize various aspects of the container, such as its name, network settings, environment variables, and more. Here is an overview of the most commonly used options and features of thedocker runcommand:First you have to modify the user and add the user ubuntu= sudo usermod -aG docker ubuntu
Then run this Command- docker run hello-world

Use the
docker inspectcommand to view detailed information about a container or image.🔷 The
docker inspectcommand is used to retrieve detailed information about Docker objects, such as containers, images, volumes, networks, and more. It provides a JSON representation of the object's configuration, status, and metadata.🔶 To inspect the container.
docker inspect containerid
Commands
docker run -d hello-world
e9bfc15e749063e513b00ff59a1377b2225aab6401fa4fd76d84d3a273f03097
docker inspect e9bfc15e749063e513b00ff59a1377b2225aab6401fa4fd76d84d3a273f03097






Use the
docker portcommand to list the port mappings for a container.🔷The
docker portcommand allows you to view the public ports that are mapped to a running Docker container. It provides information about which ports on the host system are forwarded to the container's exposed ports. This is useful for inspecting the port mappings, especially when multiple containers are running, and you need to know how to access a specific container's services.docker port container id
docker port dd63cf745c81

- Use the
docker statscommand to view resource usage statistics for one or more containers.
- Use the
🔷The docker stats command is used to display a real-time stream of resource usage statistics for running Docker containers. This command provides information on CPU, memory, network I/O, and block I/O usage for each container. It's a helpful tool for monitoring and managing container resource usage.
Docker stats container id
docker stats dd63cf745c81

Output:-

3. Use the docker top command to view the processes running inside a container.
The docker top command is used to view the running processes within a Docker container. It provides a list of processes running inside the specified container, along with details such as the process ID (PID), user, CPU usage, and more. This command can be helpful for troubleshooting and monitoring the processes within a container.
🔶Here's the basic syntax of the docker top command:
docker top container id
docker top dd63cf745c81
Output:-

4. Use the docker save command to save an image to a tar archive.
The docker save command is used to save one or more Docker images as tarball archive files. This is particularly useful when you want to export Docker images from your local system, for example, to move them to another machine or share them with others.
touch dockerfile1.tar
ls
docker save node-app -o dockerfile1.tar
docker save node-app > dockerfile1.tar

tar -tf dockerfile1.tar


5.Use the docker load command to load an image from a tar archive.
docker load: Load an image or repository from a tar archive (even if compressed with gzip, bzip2, or xz) from a file or STDIN. It restores both images and tags
docker load -i image_archive.tar
Replace image_archive.tar with the actual name of your tar archive containing the Docker image. This command will load the Docker image contained in the tar archive into your local Docker environment.
Remember, you need appropriate permissions and access to Docker to execute this command successfully.
Thank you for reading this Blog. Hope you learned something new today! If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future😊😊