How to Build and Deploy a Dockerized App

A while back, I wanted to share my app with friends without telling them to install a bunch of stuff. That’s when I learned about Docker. It made things so much easier. Now, I can wrap my app in a container, send it anywhere, and it just works.

In this guide, I’ll show you how I build and deploy a Dockerized app — step by step. Don’t worry if you’re new to this. I’ll explain everything in simple words, just like how I learned it.


What Is Docker?

Let’s start with the basics.

Docker is a tool that puts your app and everything it needs into a neat little box called a container. That container can run anywhere — on your laptop, your friend’s laptop, or a server across the world.

Imagine you’re packing for a trip. Instead of carrying loose clothes and toiletries, you use a suitcase. That’s Docker — your app’s suitcase.


Why Use Docker?

Here’s why I use Docker:

  • No more “works on my computer” problems.
  • Fast setup — I can spin up apps in seconds.
  • Portable — I can move my app from one computer to another.

It’s like giving your app superpowers. Once it’s inside a Docker container, you don’t have to worry about what’s installed on the machine running it.


What You Need First

Before you start, make sure you have:

  • Docker installed (visit docker.com)
  • A simple app to test (we’ll use a small web app)
  • A text editor (like VS Code or even Notepad)

If you don’t have Docker yet, install it using the guide on their website. It works on Windows, macOS, and Linux.


Step 1: Create a Simple App

To keep it easy, let’s make a small Python web app using Flask.

Create a folder called myapp and add a file named app.py with this code:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello, Docker!"

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)

Also, make a file called requirements.txt:

flask

This tells Docker what packages your app needs.


Step 2: Write a Dockerfile

A Dockerfile tells Docker how to build your app.

In the same folder, create a file named Dockerfile (no file extension) with this:

# Use an official Python image
FROM python:3.10-slim

# Set working directory
WORKDIR /app

# Copy files into the container
COPY . .

# Install required packages
RUN pip install -r requirements.txt

# Run the app
CMD ["python", "app.py"]

This is like a recipe. It tells Docker to:

  1. Start from a base image (Python).
  2. Put your app files in.
  3. Install the needed packages.
  4. Run the app.

Step 3: Build the Docker Image

Now that you have a Dockerfile, you can build your image.

In your terminal, run:

docker build -t my-flask-app .

This command tells Docker to read your Dockerfile and build a container image named my-flask-app.

The dot . means “use the current folder.”


Step 4: Run the App in a Container

Now that the image is ready, let’s run it:

docker run -p 5000:5000 my-flask-app

Here’s what this does:

  • -p 5000:5000 means “forward port 5000 from the container to your computer.”
  • my-flask-app is the name of your Docker image.

Now open your browser and go to:

http://localhost:5000

You should see: Hello, Docker!

If you see it, congrats — your app is running in Docker!


Step 5: Make It Run in the Background (Optional)

Sometimes you want the app to keep running while you do other things.

Run it like this:

docker run -d -p 5000:5000 my-flask-app

The -d stands for detached mode — it keeps the app running in the background.

To see running containers:

docker ps

To stop one:

docker stop [container_id]

Step 6: Share or Deploy Your App

Now that you’ve built the container, you can share it or deploy it to a server.

Three simple ways to do that:

  • Push to Docker Hub
    Make an account at hub.docker.com. Then run:

    docker tag my-flask-app yourusername/my-flask-app
    docker push yourusername/my-flask-app
    
  • Copy to a VPS
    Use scp or rsync to copy your app folder to your VPS, then build and run it there.
  • Use Docker Compose
    If your app needs a database or other services, docker-compose.yml makes it easy to manage everything.

Things I Learned the Hard Way

When I first started using Docker, I made a few mistakes. Maybe this list will help you avoid them:

  • Forgot to expose the right port — my app was running but I couldn’t access it.
  • Used wrong file paths — always check if COPY in Dockerfile matches the real file names.
  • Built too many imagesdocker images shows them all; use docker image prune to clean up.

Helpful Docker Commands

Here are a few I use often:

  • docker ps — shows running containers
  • docker stop <id> — stops a container
  • docker rm <id> — removes a container
  • docker rmi <image> — deletes an image
  • docker logs <id> — shows logs (errors, etc.)

Final Thoughts

Docker might seem like a big topic, but once you use it a few times, it feels pretty smooth. Now I can take almost any app, package it with Docker, and run it anywhere — without worrying about “missing dependencies” or weird setup steps.

If you haven’t tried Docker yet, I really think you should give it a go. Start small. Build something fun. Maybe a personal site, a to-do list app, or even a small game.

I’d love to know — what kind of app are you thinking about Dockerizing?

 

Leave a Reply