Part 1: Meet Docker - The Superhero of Software Delivery

·

6 min read

Part 1: Meet Docker - The Superhero of Software Delivery

So once was a developer named Luffy who worked days in order to create a marvelous web application The application was marvelous and all tests passed successfully on Luffy’s laptop . Convinced that his team will also love it, Luffy installed the application on another computer. Guess what? It failed miserably! They made a carry-over problem from windows, missing dependencies, mismatched versions and environmental issue transform Luffy’s victory into failure.

“It works on my machine!” Luffy cried.

But then Docker came into Luffy’s life looking like a superhero wear a cape. It promised:

“Luffy, don’t worry anymore. I will place your app and all the application components down into a container that can be easily moved from one place to another. Including its compatibility features as an operating system, it will run anywhere – on your laptop, on your server, or in the cloud”.

Alright let us now look at how Docker saved luffy and how it can save you too!

What is Docker?

Essentially, Docker is a tool that assists you in the manner of how your application and all the things it requires (code, libraries, dependencies) get “packed” into a container. You should imagine a container as a space magic—people are certain that the application will work the same way no matter where they share it.

Imagine This:

You’re baking a cake. Supposed to contain flour sugar eggs and should preferably be baked in a certain temperature to be perfect. Docker is like getting a self containing baking kit where everything is included even the actual cake and oven. It does not matter if you are in your kitchen, your friends house, or a bakery, you will have the same delicious cake.

Docker vs Virtual Machines (VMs): What’s the Difference?

Those thinking Docker is a new concept should know that, before this technology, developers used a concept known as Virtual Machines (VMs) to create isolated spaces or environments. But VMs were slow and bulky. It was like trying to transport an entire house in order to move just a couch.

Docker Containers, in another hand, are very lightweight and also very fast. And all remember when you move a couch from one room to another house? They’re that efficient and fast.

Here’s a quick comparison:

FeatureVirtual MachinesDocker Containers
SizeHeavy, gigabytesLightweight, megabytes
Startup TimeMinutesSeconds
OS DependencyFull OS requiredShares host OS
Resource UsageHighVery low

Key Docker Concepts Explained Simply

Let’s meet Docker’s key components, as if they were characters in a story:

  1. Docker Image: It’s as if an image is a description for a recipe of your application. It holds all the details required to execute your application on any platform it is built to be used on.

  2. Docker Container: A container is a prepared dish from the recipe. It is the running version of the image.

  3. Dockerfile: Dockerfile is your recipe – A series of instructions on how to build the image.

  4. Docker Hub: Since Docker Hub is seen as an image distribution platform, you can consider it a supermarket where you can grab prepared images or contribute yours.

Luffy’s First Docker Adventure

For the sake of it, decided to set up a run a web server using docker plainly. luffy also never used Docker before, but Docker makes it easy. Let’s follow luffy step by step:

Step 1: Install Docker

First, Luffy installed Docker from docker.com on the laptop.

Step 2: Run a Web Server Using Docker

Luffy wished to install a small web server known as nginx. Rather than nginx being installed as usual by luffy , the use of Docker allowed running it instantly.

Here’s what Luffy did:

docker run -d -p 8080:80 nginx

Explanation:

  • docker run: Command to start a container.

  • -d: Starts a new control to run the container in the background.

  • -p 8080:80: In the container, maps port 80 to port 8080 of Luffy’s laptop.

  • nginx: Commands Docker to use nginx from Docker Hub.

Step 3: Open the Web Server

Luffy opened a browser and went to http://localhost:8080. About time, it was magic time, Luffy was greeted with the nginx welcome page. 🎉

What happened here?

  • Docker pulled the nginx image (a small box with the nginx server).

  • Docker then executed the container and exposed it on Luffy’s laptop.

  • Within seconds, Luffy had up and running web server without any bothersome installation process.

Understanding a Dockerfile: Writing Your Own Recipe

After that, luffy wished to containerize a custom web application. Here’s what luffy did step by step:

  1. luffy created a simple HTML file for the website:

    index.html

     <html>
       <head><title>Welcome</title></head>
       <body>
         <h1>Hello from my Dockerized Web App!</h1>
       </body>
     </html>
    
  2. Luffy wrote a Dockerfile to package the app with nginx:

    Dockerfile

     # Use nginx as the base image
     FROM nginx  
    
     # Copy the HTML file into the nginx default folder
     COPY index.html /usr/share/nginx/html/index.html  
    
     # Expose port 80
     EXPOSE 80
    
  3. Luffy built the Docker image:

     docker build -t my-web-app .
    
  • docker build: Saves an image using the Dockerfile.

  • -t my-web-app: Names the image "my-web-app".

  • .: Says that one must tell Docker to search from the current directory for Dockerfile.

  1. Luffy ran the image as a container:

     docker run -d -p 8080:80 my-web-app
    
  2. Finally, Luffy opened http://localhost:8080 and saw:
    “Hello from my Dockerized Web App!”

Docker in Real Life: How It Helps Developers

Docker made Luffy’s life much easier:

  • Finally put paid to the ‘It works fine on my machine’ excuse.

  • The application was portable—Luffy could run the app everywhere.

  • It was fast and light weight — no need for heavy installations..

  • He was now able to deploy the app to teammates simply by offering Docker image. It was like handing over a neatly packed box with instructions:

“ Just run this box and everything will become as it should ”

Key Takeaways for Today

  • Docker assist you in ‘moving’ your app into transportable containers.

  • Storing data in containers means that you clearly wins on lightness, speed and on heterogeneity because the same type of container can run on many different platforms.

  • It takes only one command to run existing applications (for example nginx) via docker run.

  • What makes Docker valuable is that it lets you containerize [our final very specific application, yes].

📝 Next will be - Part 2: We’ll explore more Docker magic:

  • Learn how to create apps with multiple containers, by following the Docker Compose tutorial.

  • Real life scenarios, let’s say containerizing a Python or Node.js app.

  • How to store and also export your docker images.

Stay tuned as we continue the Docker adventure! 🚀

See You In Next Adventure!! 🌟

If you found this part helpful, please consider subscribing to my blog for more insights and tutorials! 🌟 Your support means a lot and helps me continue sharing knowledge and resources.

Also, if you enjoyed this content, please leave a like ❤️! Your feedback is invaluable and encourages me to keep creating more valuable content.

Keep experimenting with the code, and don’t hesitate to modify and play around with it. Happy coding!💻🚀 like this ending