Skip to main content

Command Palette

Search for a command to run...

Day 16 Docker Tutorial for DevOps Engineers

Published
โ€ข5 min readโ€ขView as Markdown
S

Hi, I'm Syed Dadapeer! I'm an experienced ๐‚๐ข๐ญ๐ซ๐ข๐ฑ ๐€๐๐ฆ๐ข๐ง๐ข๐ฌ๐ญ๐ซ๐š๐ญ๐จ๐ซ and ๐’๐ฒ๐ฌ๐ญ๐ž๐ฆ ๐„๐ง๐ ๐ข๐ง๐ž๐ž๐ซ with over 2.5 years of IT experience, focusing on troubleshooting complex issues, cloud computing, virtualization, and Citrix products. I'm also ๐‘๐ž๐ ๐‡๐š๐ญ ๐œ๐ž๐ซ๐ญ๐ข๐Ÿ๐ข๐ž๐! ๐Ÿ’ก Iโ€™m passionate about learning new technologies and applying them to real-world challenges. Iโ€™m also exploring the exciting fields of ๐€๐ซ๐ญ๐ข๐Ÿ๐ข๐œ๐ข๐š๐ฅ ๐ˆ๐ง๐ญ๐ž๐ฅ๐ฅ๐ข๐ ๐ž๐ง๐œ๐ž, ๐‚๐ฅ๐จ๐ฎ๐ ๐‚๐จ๐ฆ๐ฉ๐ฎ๐ญ๐ข๐ง๐ , and ๐ƒ๐ž๐ฏ๐Ž๐ฉ๐ฌ.โ™พ๏ธ ๐Ÿš€ Letโ€™s connect! Iโ€™m always open to new opportunities and collaborations. Feel free to reach out via ๐‹๐ข๐ง๐ค๐ž๐๐ˆ๐ง or at ๐ฌ๐๐š๐๐ฎ2206@๐ ๐ฆ๐š๐ข๐ฅ.๐œ๐จ๐ฆ.

Welcome to another exciting adventure in the world of Docker! ๐ŸŽ‰ Now that you've got Docker installed and ready to go, it's time to roll up your sleeves and dive into some cool commands that will make managing your containers a breeze. ๐Ÿš€

Imagine youโ€™re the captain of a spaceship (your container) ready to launch into the unknown (your app environment). With Docker, you have all the tools you need packed and ready for the journey. All you need to do is give the command, and whoosh โ€“ youโ€™re up and running!

In this blog, weโ€™ll explore how to interact with Docker like a pro by using simple commands that will help you start containers, inspect them, check their resource usage, and much more! Whether youโ€™re saving a snapshot of your image, loading it back, or keeping track of whatโ€™s happening inside your containers, weโ€™ve got you covered. ๐ŸŒ

Tasks We're Going to Tackle:

  • Start a new container: Fire up a fresh container with the docker run command.

  • Inspect a container: Peek inside and get all the details using docker inspect.

  • Check port mappings: Know which doors your container is using with docker port.

  • Monitor resource usage: Keep an eye on your containerโ€™s health with docker stats.

  • View running processes: See what's cooking inside with docker top.

  • Save and load images: Move containers around like a pro chef with docker save and docker load.

By the end of this blog, you'll be confident enough to manage your containers.

Letโ€™s jump in and start playing around with Docker commands! Ready? Let's go! ๐Ÿš€


TASKS:

1. Running a Container: Hello Docker! ๐Ÿ‘‹

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

    First things first, letโ€™s get a container up and running. Think of Docker containers like mini virtual machines. The docker run command is like telling Docker, "Hey, I want to start a new container and run something inside it." A great way to test if Docker is working on your machine is by running the hello-world image. This command does two things:

    • It downloads the hello-world image (if not already on your system).

    • It runs the container and prints a friendly greeting message.

Command:

    docker run hello-world

If everything is set up correctly, youโ€™ll see a nice message telling you that Docker is up and running! ๐ŸŽ‰


2. Inspecting Your Container: Dive Into the Details ๐Ÿ”

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

    Curious about whatโ€™s inside a container or image? The docker inspect command gives you a detailed breakdown, like an X-ray view of your container. Use docker inspect to get all the juicy details, like configuration, environment variables, network settings, and more.

    Command:

      docker inspect <container_id_or_image_name>
    

    Just replace <container_id> with the actual ID of the container (you can get it by running docker ps). Youโ€™ll get a huge chunk of information, but it's super useful when you're debugging or want to learn more about how your containers or images are configured. ๐Ÿ’ก


3. Checking Port Mappings: Whereโ€™s the Traffic Going? ๐ŸŒ

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

    Containers often talk to the outside world via ports. To see which ports are mapped from the container to your system, use docker port. It shows you the connection between your container and your computerโ€™s ports.

    Command:

      docker port <container_id_or_name>
    

    This will display the ports on your computer that are linked to the ones inside the container. Think of it like knowing which door in your house leads to which room in your Docker world!


4. Monitoring Resource Usage: Is Your Container Healthy? ๐Ÿ’ช

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

    Worried about how much CPU, memory, or network your container is using? Enter docker stats! Itโ€™s like the fitness tracker for your containers, showing you live resource usage.

    Command:

      docker stats
    

    It will list all running containers and their resource stats. If you want to focus on a specific container, just add its ID:

      docker stats <container_id>
    

    This helps you spot if a container is taking too much power (or not enough!).

    This command will continuously show resource usage for all running containers. You can stop it anytime by pressing Ctrl + C.


5. View Running Processes: Whatโ€™s Going On Inside? ๐Ÿง‘โ€๐Ÿ’ป

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

    Inside every container, processes are running. To see whatโ€™s happening under the hood, use docker top. Itโ€™s like peeking into the containerโ€™s task manager.

    Command:

      docker top <container_id_or_name>
    

    This command shows you a list of processes (like a mini-task manager) inside your container. It's a handy way to see if everything is running smoothly or if something's stuck!


6. Saving a Docker Image: Keep a Copy for Later! ๐Ÿ’พ

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

    Need to backup or share a Docker image? The docker save command lets you save an image as a .tar file (a type of archive file). This is helpful when you want to transfer images between different systems.

    Command:

      docker save -o <filename.tar> <image_name>
    

    For example:

      docker save -o myimage.tar my-image
    

    This command saves the image as a file named my_image.tar. You can use it to back up your image, share it with others, or store it for later use.


7. Loading Images: Bring Your Image Back to Life ๐Ÿ”„

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

    Got a saved image and want to bring it back into Docker? docker load helps you load images from a tar archive. Itโ€™s like unzipping a file and bringing it back into your Docker environment!

    Command:

      docker load -i <filename.tar>
    

    For example:

      docker load -i myimage.tar
    

    This will load the image from the file, and youโ€™ll be able to run containers from it just like before!


Wrapping It Up ๐ŸŽ‰

These Docker commands are powerful tools for interacting with containers, inspecting their health, managing resources, and even backing up your favorite images. Whether you're just starting or youโ€™ve been using Docker for a while, mastering these commands will make your life easier and more fun. Happy Docking! ๐Ÿณ

Have you tried any of these commands yet? Share your experience with us in the comments!

Keep experimenting, and happy Dockering! ๐Ÿšข

90DaysOfDevOps

Part 16 of 27

Iโ€™m ๐›๐ž๐ฒ๐จ๐ง๐ ๐ž๐ฑ๐œ๐ข๐ญ๐ž๐ for the incredible journey ahead ๐Ÿš€! Ready to dive deep into DevOps ๐Ÿ’ป. ๐‹๐ž๐ญโ€™๐ฌ ๐ฆ๐š๐ค๐ž ๐ฆ๐š๐ ๐ข๐œ ๐ก๐š๐ฉ๐ฉ๐ž๐ง! ๐Ÿ”ฅ Throughout this journey, Iโ€™ll be sharing my progress and key learnings!

Up next

Day 17 DevOps Task: Hands-on Docker Project for Engineers

Ever wonder how your favorite apps and websites run smoothly, no matter where you access them from? ๐ŸŒ Well, a lot of that magic happens behind the scenes with tools like Docker! Think of Docker as a little box ๐Ÿ“ฆ that holds your entire app and all t...

More from this blog

Untitled Publication

30 posts