Enhancing Skills

Docker Commands: A Simple Guide

In this article, we will introduce the most common and helpful Docker commands to a fifth grader in an easy-to-understand way. By learning these commands, you’ll be able to work with Docker containers more effectively!

Table of Contents

Introduction

Hey there, little buddy! Today, we’re going to learn about Docker commands. Docker is a tool that helps you run and manage programs in special “containers.” These containers make it easy to work with different software without needing to install everything on your computer. Let’s explore some of the most useful Docker commands!

Basic Commands

  1. docker version: This command shows you the version of Docker you have installed. It’s like checking if your toy is a new model or an older one.
docker version
  1. docker info: This command gives you information about your Docker setup, like how much space it uses.
docker info
  1. docker ps: This command shows you a list of all the containers that are currently running. It’s like seeing all your friends who are playing with you right now!
docker ps
  1. docker stats: is a command used in Docker to provide real-time statistics about the resource usage of your running Docker containers. It displays details such as CPU usage, memory usage, network I/O, and block I/O for each container. This command helps monitor the performance and resource consumption of containers.
docker stats [OPTIONS] [CONTAINER...]

docker stats --format "{{.Name}}: {{.CPUPerc}} {{.MemUsage}}"

CONTAINER ID   NAME               CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O   PIDS
c0555ae96778   nas1               0.00%     36KiB / 5.813GiB      0.00%     7.32kB / 3.19kB   0B / 0B     0
b036db016056   nas2               0.00%     36KiB / 5.813GiB      0.00%     27.8kB / 15.4kB   0B / 0B     0
9ce280a0419d   nas3               0.00%     36KiB / 5.813GiB      0.00%     4.98kB / 0B       0B / 0B     0
07c181fe4a77   nss4               0.00%     36KiB / 5.813GiB      0.00%     6.71kB / 860B     0B / 0B     0
91d87a37ad23   website1           5.50%     81.31MiB / 5.813GiB   1.37%     5.06GB / 7.51GB   0B / 0B     0
2192556899d3   sdk                0.00%     4KiB / 5.813GiB       0.00%     0B / 0B           0B / 0B     0
aa3e990fa5b7   website2          72.81%    250MiB / 512MiB       48.82%     5.54GB / 943MB    0B / 0B     0
08fb250a644f   website2-d         1.22%     58.1MiB / 512MiB      11.35%    1.88GB / 14.4GB   0B / 0B     0
a49c92560077   website3           0.00%     59.18MiB / 5.813GiB   0.99%     14MB / 4.99MB     0B / 0B     0

FieldDescription
CONTAINER IDThe ID of the container.
NAMEThe name of the container.
CPU %CPU usage as a percentage of the total host capacity.
MEM USAGE / LIMITMemory used by the container, followed by the total memory limit.
MEM %Memory usage as a percentage of the container’s memory limit.
NET I/OThe amount of network input and output (sent/received).
BLOCK I/OBlock storage input and output (e.g., disk I/O).
PIDSThe number of processes or threads in the container.

Building Images

Docker images are like special blueprints for your containers. They have everything needed to run a program. Here are some important commands to work with Docker images:

  1. docker build: This command helps you create a new Docker image from a recipe called a “Dockerfile.” It’s like building a toy from instructions!
docker build -t *your_image_name* .

Replace “your_image_name” with the name you want to give your new image. The dot (.) at the end tells Docker to use the current directory as the build location.

  1. docker images: This command shows you a list of all the Docker images you have on your computer, like seeing all the toys you own!
docker images

Working With Containers

Now let’s learn some commands to work with containers:

  1. docker run: This command starts a new container from one of your Docker images. You can think of it like inviting a friend to play!
docker run -t -i *your_image_name*

Replace “your_image_name” with the name of the image you want to use. The -t and -i flags tell Docker to give your container a virtual terminal and keep it interactive, like playing a game where you can see what’s happening inside!

  1. docker start: This command starts a container that is already stopped, like waking up a sleeping friend.
docker start *container_id*

Replace “container_id” with the ID of the container you want to start.

  1. docker stop: This command stops a running container, like telling your friend it’s time for a nap.
docker stop *container_id*

Replace “container_id” with the ID of the container you want to stop.

Commands I use most

For a list of most common commands I use: please visit: Docker commands I use the most

Summary

Now you know some of the most important Docker commands for kids! You can build images, run containers, and manage your Docker world more easily. Keep exploring and have fun learning about Docker


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.