- Published on
How to Use Docker to Containerize Your Apps in 5 Minutes
Docker is a tool that allows you to package an application and all its dependencies into a single "container" that runs consistently on any computer. By using Docker, you can eliminate the "it works on my machine" problem and deploy software in under 5 minutes regardless of the underlying operating system. Most beginners can containerize their first Python or Node.js application by writing a simple 5-line configuration file called a Dockerfile.
Why should you use Docker for your projects?
Docker solves the problem of environment inconsistency by creating an isolated sandbox for your code. When you share a project, the recipient doesn't need to manually install specific versions of databases or languages. They simply run your container, and everything works exactly as it did on your laptop.
This isolation also means you can run multiple versions of the same software on one machine without them clashing. For example, you could run a legacy project using Python 3.10 alongside a modern one using Python 3.15. Each project stays in its own bubble, unaware of the other.
We've found that using Docker significantly reduces the time spent on "DevOps" (the practice of managing how code is deployed and run). Instead of writing long setup guides for your teammates, you provide a single file that automates the entire process. This allows you to focus more on building features and less on fixing broken installations.
What do you need before getting started?
To follow this guide, you should have a basic understanding of using a terminal (the text-based interface for your computer). You will also need a few modern tools installed to make the process easier.
- Docker Desktop: This is the main application that manages your containers. Download the latest version from the official website.
- VS Code with AI Extensions: Use Visual Studio Code with the latest AI-assisted tools like Claude 4.5 or GPT-5 integrations. These tools can help you write Dockerfiles by suggesting the correct syntax for your specific language.
- Python 3.15: While Docker handles the environment, having the latest stable version of Python on your local machine helps with initial testing.
- Node.js 24: If you are building web apps, ensure you have the current Long Term Support (LTS) version.
How do you create your first Docker image?
A Docker image is a read-only template that contains the instructions for creating a Docker container. Think of the image as a recipe and the container as the actual meal. To create an image, you need to write a Dockerfile (a text file with no extension that contains the assembly instructions).
Step 1: Create a simple application
Create a new folder and add a file named app.py. Paste the following code into it:
# A simple script that prints a message
print("Hello from inside the Docker container!")
What you should see: You should have a folder with a single .py file inside it.
Step 2: Write the Dockerfile
In the same folder, create a new file named Dockerfile. Add these lines:
# Use the official Python 3.15 image as a starting point
FROM python:3.15-slim
# Set the working directory inside the container to /app
WORKDIR /app
# Copy the local app.py file into the container's /app folder
COPY app.py .
# Tell the container to run our script when it starts
CMD ["python", "app.py"]
What you should see: A file named Dockerfile (make sure it doesn't have a .txt extension) sitting next to your app.py.
Step 3: Build the image
Open your terminal inside that folder. Run the following command to "build" your image:
# 'docker build' creates the image
# '-t my-first-app' gives it a name (tag)
# '.' tells Docker to look in the current folder
docker build -t my-first-app .
What you should see: The terminal will download the Python "base image" and execute your steps. You'll see a message saying "Successfully tagged my-first-app:latest."
Step 4: Run the container
Now that the image is built, you can turn it into a running container. Run this command:
# 'docker run' starts a container based on your image
docker run my-first-app
What you should see: The terminal should output: Hello from inside the Docker container!.
How do you manage containers and images?
Once you start building more projects, your computer will start filling up with images and containers. You need to know how to view and clean them up so they don't take up too much disk space.
You can see all the images currently stored on your machine by running docker images. This list shows you the name, the size, and when the image was created.
To see which containers are currently running, use the command docker ps. If you want to see all containers, including the ones that have finished running, use docker ps -a.
Cleaning up is just as important as building. Use docker rm [container_id] to remove a specific container or docker rmi [image_id] to delete an image. If you want to clear out everything that isn't being used, run docker system prune.
What are the common mistakes beginners make?
It is normal to feel a bit confused when your first build fails. Most errors come from small syntax mistakes or misunderstandings of how Docker views your files.
One common mistake is forgetting the "context." When you run docker build ., the . represents the current folder. If your Dockerfile is in a different folder than your code, Docker won't be able to find the files you are trying to COPY.
Another "gotcha" is the size of the images. If you use a standard base image like FROM python:3.15, the resulting image might be over 1GB. Don't worry if this happens; you can use "slim" or "alpine" versions (like python:3.15-slim) to keep your images small and fast.
Finally, remember that containers are "ephemeral" (temporary). Any files you save inside a container will disappear once the container is deleted. If you need to save data permanently, you'll need to learn about "Volumes" (a way to link a folder on your computer to a folder inside the container).
Next steps for your Docker journey
Now that you've run a basic script, you should try containerizing a web server. Try using a framework like FastAPI or Next.js 15 and see if you can get a website running inside a container. You'll need to learn how to "map ports" (connecting a port on your computer to a port inside Docker) so you can view the site in your browser.
As you progress, look into Docker Compose. This tool allows you to run multiple containers at once, such as a web app and a database, using a single configuration file. It is the standard way solopreneurs build and test full-stack applications today.
For detailed guides and API references, visit the official Docker documentation.