DEV Community

Cover image for Getting Started with Docker: First Steps 🐳
Egzont
Egzont

Posted on

Getting Started with Docker: First Steps 🐳

Ever heard "It works on my machine"? Docker solves that.

Here’s a quick step-by-step to get started with Docker—no fluff, just the essentials. 🚀

🛠 Prerequisites
Docker installed: https://www.docker.com/products/docker-desktop
Basic knowledge of terminal/command line

1️⃣ Create a Simple App

Let’s build a basic Python app.

docker-tutorial/
├── app.py
└── requirements.txt

Enter fullscreen mode Exit fullscreen mode

📝 app.py

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello from Docker!"

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

Enter fullscreen mode Exit fullscreen mode

📝 requirements.txt

flask
Enter fullscreen mode Exit fullscreen mode

2️⃣ Create a Dockerfile
In the same folder, create a file called Dockerfile (no extension):

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

# Set the working directory
WORKDIR /app

# Copy files to container
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .

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

Enter fullscreen mode Exit fullscreen mode

3️⃣ Build Your Image
Open terminal in your project folder and run:

docker build -t hello-docker .

Enter fullscreen mode Exit fullscreen mode

4️⃣ Run Your Container

docker run -d -p 5000:5000 hello-docker

Enter fullscreen mode Exit fullscreen mode

Go to your browser and visit: http://localhost:5000 🎉

🧹 Clean Up

Stop and remove all containers:

docker ps -a
docker stop <container_id>
docker rm <container_id>

Enter fullscreen mode Exit fullscreen mode

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

Image of Timescale

📊 Benchmarking Databases for Real-Time Analytics Applications

Benchmarking Timescale, Clickhouse, Postgres, MySQL, MongoDB, and DuckDB for real-time analytics. Introducing RTABench 🚀

Read full post →

👋 Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay