DEV Community

Cover image for Docker is easier than you think!
Idil Saglam
Idil Saglam

Posted on

Docker is easier than you think!

I promise that after reading this post, you'll understand what Docker does and how it works. Docker might seem a bit abstract at first, but it's a really useful tool for developers. I read so many articles about it, but it's simpler than you think!

I'm going to explain Docker in the simplest terms possible so you can understand why it's important to use and how it can easily fit into your projects. Let's dive in!

Let's say you built an app on your laptop and it works great. But then when you send it to your friend, it doesn't work on their computer.🥺

Why? Your friend's computer might have a different version of the software or need certain tools for your app to run. This can be frustrating, huh? I don't even talk about the cases in which you don't send your cool app to a friend to try it, so it can cause massive problems if it's a job interview or a project you delivered to your client.

It would be great if you could create a box that includes everything it needs to work. No matter where you send this box—to your friend's computer, a server, or even the cloud—it will work the same way.

magic box

Good news is that it exists, and it is called a container on Docker.🥳

What is Docker?

Docker is like the creators of these boxes. It helps you package your app and everything it needs into a box (container). Inside the box, there is

  • Your code
  • All the tools and libraries your app needs to run
  • Settings that make sure your app runs correctly

Once your app is inside this Docker box, it can run anywhere. You don't have to worry about whether it will work on different computers or environments because everything your app needs is already packed inside!

Why use Docker?

Your app works the same everywhere, whether on your laptop, your friend's computer, or a remote server.
Each app runs in its own box, so there are no conflicts with other apps.

You can easily share this Docker container with others, and it will work right out of the box, no extra setup needed.

Fancy terms that you need to understand

Dockerfile:

It tells Docker what to put in the box (container) and how to set everything up. For example, if your app uses Node.js, you tell Docker in the Dockerfile to install Node.js inside the container.

FROM node:14     # Start with a basic Node.js environment
WORKDIR /app     # Create a folder in the container for your app
COPY . .         # Copy your app code into the container
RUN npm install  # Install all the necessary packages
EXPOSE 3000      # Make sure port 3000 is available
CMD ["npm", "start"] # Start your app

Enter fullscreen mode Exit fullscreen mode

Docker image:

Docker image doesn't actually do anything by itself, but it contains everything needed to set up and run your app when turned into a container. Here is an analogy that I like to explain what docker image is:

Think of a Docker image like a frozen pizza you buy from the store:
When the pizza is frozen, you can't eat it yet. But it has everything you need to make a meal: the dough, sauce, cheese, and toppings are all there.You just need to put it in the oven (run it) to make it ready to eat.

Similarly, a Docker image has all the things your app needs to run (code, software, libraries). It's like the frozen version of your app.

pizza

So in the docker image there is your code, dependencies that your app needs and any special settings your app needs to work correctly.

Docker container

Is a running instance of a docker image. In our analogy its like putting that frozen pizza in the oven and baking it. Now, the pizza is hot and ready to eat, meaning it's actually useful.

Good to know

Docker image is just a package with your app and all the dependencies
Docker container is when you tell Docker to "run" the image it creates a container. This container is where your app is actually running.

In Super Simple Terms:
Docker is like putting your app in a box so it works the same everywhere.Inside this box, your app has everything it needs to run (the right version of Node.js, libraries, etc.).

You can send this box (Docker container) to anyone, and it will work without any issues, even if their computer is different.

Why You Should Care:

You don't need to worry about things like "It works on my computer but not on the server."It's easy to share your app with others, and they can run it with a single command.You can avoid all the messy setup of environments and dependencies!

In short, Docker helps you create a clean, isolated environment for your app that you can run anywhere, without worrying about things breaking because of differences in the environment.
Hope its clearer now.

Top comments (0)