• Skip to main content
  • Skip to primary navigation
  • Skip to primary sidebar
  • Skip to footer
codesamplez.com
  • Home
  • Featured
    • Advanced Python Topics
    • AWS Learning Roadmap
    • JWT Complete Guide
    • Git CheatSheet
  • Explore
    • Programming
    • Development
      • microservices
      • Front End
    • Database
    • DevOps
    • Productivity
    • Tutorial Series
      • C# LinQ Tutorials
      • PHP Tutorials
  • Dev Tools
    • JSON Formatter
    • Diff Checker
    • JWT Decoder
    • JWT Generator
    • Base64 Converter
    • Data Format Converter
    • QR Code Generator
    • Javascript Minifier
    • CSS Minifier
    • Text Analyzer
  • About
  • Contact
You are here: Home / DevOps / Create Multi-Container Docker Application from Scratch

Create Multi-Container Docker Application from Scratch

Updated April 23, 2025 by Rana Ahsan Leave a Comment ⏰ 3 minutes

multi container docker application

In this tutorial, we’ll walk through the process of containerizing a multi-container Docker application using “Docker Compose.” We’ll create a simple web application consisting of a Python Flask backend, a Redis database, and an Nginx web server.

Note: This post has been updated to reflect the usage change from “fig” , which is the predecessor to “docker-compose”

Prerequisites:

  • Docker installed on your machine (version 20.10 or later)
  • Docker Compose installed on your machine (comes bundled with Docker)
  • Basic knowledge of Docker and containerization. Refer to docker guides for more details on how to get started.

Step 1: Create the Project Structure

Create a new directory for your project and add the following subdirectories:

mkdir myapp
cd myapp
mkdir app redis nginx

Step 2: Create the Flask Application

In the app directory, create a new file called app.py with the following content:

from flask import Flask
from redis import Redis

app = Flask(__name__)
redis = Redis(host='redis', port=6379)

@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)Code language: JavaScript (javascript)

Step 3: Create the Redis Configuration

In the redis directory, create a new file called redis.conf with the following content:

port 6379

Step 4: Create the Nginx Configuration

In the nginx directory, create a new file called nginx.conf with the following content:

http {
    server {
        listen 80;
        server_name localhost;

        location / {
            proxy_pass http://app:5000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }
}Code language: PHP (php)

Step 5: Create the Dockerfiles

Create a new file called Dockerfile in each of the app, redis, and nginx directories:

Location: app/Dockerfile

FROM python:3.9-slim

WORKDIR /app

COPY requirements.txt .

RUN pip install -r requirements.txt

COPY . .

CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"]Code language: JavaScript (javascript)

Location: redis/Dockerfile

FROM redis:alpine

COPY redis.conf /etc/redis/redis.conf

CMD ["redis-server", "/etc/redis/redis.conf"]Code language: JavaScript (javascript)

Location: nginx/Dockerfile

FROM nginx:alpine

COPY nginx.conf /etc/nginx/nginx.conf

CMD ["nginx", "-g", "daemon off;"]Code language: JavaScript (javascript)

Step 6: Create the Docker Compose File

In the main application root directory, create a new file called docker-compose.yml (or just compose.yml if you are using the new “docker compose” command) with the following content:

services:
  app:
    build: ./app
    ports:
      - "5000:5000"
    depends_on:
      - redis
    environment:
      - REDIS_HOST=redis

  redis:
    build: ./redis
    ports:
      - "6379:6379"

  nginx:
    build: ./nginx
    ports:
      - "80:80"
    depends_on:
      - appCode language: JavaScript (javascript)

Step 7: Let’s Run the Multi-Container Docker Application!

Run the following command to build and start the containers:

docker-compose up
#or
docker compose up
Code language: CSS (css)

Open your web browser and navigate to http://localhost to see the application in action.

Note:

  • If port 80 is occupied by another service running on your machine, change the Nginx port from “80” to something else(e.g., “8000,” etc.).
  • If you are confused about whether to use “docker-compose ” instead of “docker-compose,” please refer to the forum discussion for more information.

Conclusion

In this tutorial, we’ve successfully orchestrated a multi-container application using Docker and Docker Compose. We’ve created a Flask application, a Redis database, and an Nginx web server, and demonstrated how to manage and orchestrate them using Docker Compose. Also, as you continue developing your application, don’t forget to auto-reload your docker environment. If there are any follow-up questions/comments, please comment below.

Share if liked!

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Reddit (Opens in new window) Reddit
  • Share on Tumblr (Opens in new window) Tumblr

You may also like


Discover more from CodeSamplez.com

Subscribe to get the latest posts sent to your email.

First Published On: February 14, 2015 Filed Under: DevOps Tagged With: deployment, docker, nginx, python, redis

About Rana Ahsan

Rana Ahsan is a seasoned software engineer and technology leader specialized in distributed systems and software architecture. With a Master’s in Software Engineering from Concordia University, his experience spans leading scalable architecture at Coursera and TopHat, contributing to open-source projects. This blog, CodeSamplez.com, showcases his passion for sharing practical insights on programming and distributed systems concepts and help educate others.
Github | X | LinkedIn

Reader Interactions

Leave a ReplyCancel reply

Primary Sidebar

  • Facebook
  • X
  • Pinterest
  • Tumblr

Subscribe to Blog via Email

Featured Dev Tools

  • JWT Decoder
  • Diff Checker

Top Picks

python local environment setup

Python Local Development Environment: Complete Setup Guide

In-Depth JWT Tutorial Guide For Beginners

JSON Web Tokens (JWT): A Complete In-Depth Beginners Tutorial

The Ultimate Git Commands CheatSheet

Git Commands Cheatsheet: The Ultimate Git Reference

web development architecture case studies

Web Development Architecture Case Studies: Lessons From Titans

static website deployment s3 cloudfront

Host Static Website With AWS S3 And CloudFront – Step By Step

Recently Published

visual diff github

SnapDrift: Free Auto Visual Regression Testing On GitHub Actions

Local Coding Agent

Local LLM for Coding: Free AI Coding Agent With Ollama + Claude

Best AI Coding Agents

Best AI Coding Agents in 2026: The Complete Beginner’s Guide

RAG Systems In Python

A step-by-step guide to building a simple RAG system in Python

Add Memory To AI Agents

Add Memory to AI Agent: Python Tutorial for Beginners

Footer

Subscribe to Blog via Email

Demos

  • Demo.CodeSamplez.com
  • Facebook
  • X
  • Pinterest
  • Tumblr

Explore By Topics

Python | AWS | PHP | C# | Javascript

Copyright © 2026