Docker Journey

KARTIK KAKODIYAKARTIK KAKODIYA
3 min read

Docker Journey: From Zero to Hero

Introduction

Today, I embarked on a Docker journey, starting from cloning a repository to running multi-stage builds. The experience was full of learning and challenges. Here's a detailed account of my day, the commands I used, and the lessons learned.

Cloning the Repository

The first step was to clone the Docker-Zero-to-Hero repository from GitHub. This repository is a great starting point for anyone looking to get hands-on experience with Docker.

git clone git@github.com:aut0b0ts/Docker-Zero-to-Hero.git
cd Docker-Zero-to-Hero/examples
ls

Building and Running Docker Images

I began with building a simple Docker image and running a container from it. Here are the steps I followed:

  1. Logging into Docker:

     docker login
    
  2. Building the Docker Image:

     docker build -t kaka750/test01 first-docker-file
    
  3. Listing Docker Images:

    
     docker images
    
  4. Running the Docker Container:

     docker run -it kaka750/test01
    
  5. Pushing the Docker Image to Docker Hub:

     docker push kaka750/test01
    

Challenges Faced

During this phase, I encountered some challenges:

  • Incorrect Commands: I mistakenly used incorrect commands such as docker images head -2 and docker images -5 head. The correct way to list images is just docker images.

  • Typos: There was a typo in the command docker push kaka750/text01 which should have been docker push kaka750/test01.

Building a Python Web App Docker Image

Next, I worked on a Python web application:

  1. Navigating to the App Directory:

     cd python-web-app
     vi Dockerfile
    
  2. Building the Docker Image:

     docker build -t kaka750/test02 python-web-app
    
  3. Running the Container:

     docker run -p 8080:3000 kaka750/test02
    
  4. Inspecting the Container:

     docker inspect 093fa6c7d75e
    
  5. Fixing Issues: There were several attempts to build and run the container, indicating some trial and error. Adjustments in the Dockerfile were necessary to get the application running correctly.

Learning Points

  • Dockerfile Syntax: Proper understanding of Dockerfile syntax and directives is crucial. Mistakes in the Dockerfile can lead to multiple build failures.

  • Port Mapping: Correctly mapping ports (-p 8080:3000) is essential to access the running application.

Exploring Multi-Stage Builds

Finally, I explored multi-stage builds with a Go application:

  1. Navigating to the Directory:

     cd golang-multi-stage-docker-build/dockerfile-without-multistage
     vi Dockerfile
    
  2. Building and Running the Docker Image:

     docker build -t withoutmulti/staging .
     docker run withoutstaging
    
  3. Switching to Multi-Stage Build:

     docker build -t withstaging .
     docker run withstaging
    

Challenges and Learning

  • Multi-Stage Builds: Understanding the benefits of multi-stage builds in reducing image size and improving build efficiency.

  • Debugging Builds: Fixing issues related to build context and dependencies in the Dockerfile.

Conclusion

Today's journey with Docker was enlightening. From simple builds to complex multi-stage ones, I faced several challenges but learned a lot in the process. Docker is a powerful tool for containerization, and with each step, I am becoming more proficient in using it effectively.

Feel free to reach out if you have any questions or need further assistance in your Docker journey. Happy containerizing!

0
Subscribe to my newsletter

Read articles from KARTIK KAKODIYA directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

KARTIK KAKODIYA
KARTIK KAKODIYA