What is Docker Compose and why use it?

Good morning everyone and welcome to a new article from Tooldech. In this article, we’ll talk about a useful tool when working with… Docker…you’ve probably noticed that starting multiple containers with… docker run …can quickly become complicated. Imagine having to launch a web application with a database, a cache server, and maybe a reverse proxy: lots of commands, ports to remember, networks to create…

This is where comes into play. Docker Compose— a tool that allows you to define and run multi-container Docker applications. more container Docker through a single unice file YAMLIt’s perfect for creating development environments that are replicable, readable, and easy to maintain.


How it works

Docker Compose works through a file called docker-compose.yml, where you define:

  • The services (es. app, database…),
  • The networks that connect them,
  • any necessary volumes persistent
  • and all the configurations needed to launch the entire stack.

Once the file is ready, a single command is enough to start everything:

docker-compose up

Prerequisites

Before getting started, make sure you have installed:

Or check out my article on theinstallazione di docker.

Verifiy all with :

docker --version
docker compose version

Let’s create our first local environment

In this guide, we’ll create a demo application made up of:

  • a server web (based of Nginx)
  • a database PostgreSQL

1. Structure of project

Make a folder for the project

mkdir mio-progetto-docker
cd mio-progetto-docker

Inside it, we’ll create two files:

  • `docker-compose.yml` → defines the services
  • index.html → un file HTML di test per il web server

2. Let's write the docker-compose.yml file

version: '3.8'

services:
  web:
    image: nginx:latest
    ports:
      - "8081:80"
    volumes:
      - ./index.html:/usr/share/nginx/html/index.html:ro
    depends_on:
      - db

  db:
    image: postgres:13
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
      POSTGRES_DB: miaapp
    volumes:
      - db_data:/var/lib/postgresql/data

volumes:
  db_data:

Detailed explanation:

  • version: '3.8': version of the Compose file format.
  • services: definisce i container.
  • web:
    • uses the official nginx image.
    • exposes port 8081 on your PC to port 80 of the container.
    • mounts index.html into Nginx's default directory.
    • dipende dal database (depends_on).
  • db:
    • uses the official postgres:13 image.
    • sets environment variables for user, password, and initial database.
    • creates a persistent volume named db_data.
  • volumes: definition of named volumes (persistent)

If you want to download the file docker-compose to get head start, here it is:


3. Let's create the file index.html

In the project, create the html file:


4. Start the environment"

Start everything with:

docker-compose up

You'll see the container logs starting up. If this is the first time, Docker will download the required images.


5. Test that it's working

Open your browser and go to:

http://localhost:8081

you 'll see the text:

In the meantime, the PostgreSQL container will be running, ready to accept connections from your app.


Useful Docker Compose commands

  • Start in background:
docker-compose up -d
  • Stop the services:
docker-compose down
  • Verifiy the status:
docker-compose ps
  • Log from container:
docker-compose logs -f

Conclusion

You've just created your first local development environment with Docker Compose — simple, readable, and powerful.

This is the perfect foundation for building more complex applications by integrating backend, frontend, databases, queues, proxies, and more. With a single file, you can manage your entire stack!

We've reached the end of this simple and interesting article on Docker Compose. Thanks for reading, and see you in the next one!

Follow us on our social media!

6 thoughts on “Docker Compose: guida semplice”
  1. Your passion for your subject matter shines through in every post. It’s clear that you genuinely care about sharing knowledge and making a positive impact on your readers. Kudos to you!

  2. Your blog is a beacon of light in the often murky waters of online content. Your thoughtful analysis and insightful commentary never fail to leave a lasting impression. Keep up the amazing work!

  3. Your writing is like a breath of fresh air in the often stale world of online content. Your unique perspective and engaging style set you apart from the crowd. Thank you for sharing your talents with us.

  4. I do believe all the ideas youve presented for your post They are really convincing and will certainly work Nonetheless the posts are too short for novices May just you please lengthen them a little from subsequent time Thanks for the post

  5. I have read some excellent stuff here Definitely value bookmarking for revisiting I wonder how much effort you put to make the sort of excellent informative website

  6. Magnificent beat I would like to apprentice while you amend your site how can i subscribe for a blog web site The account helped me a acceptable deal I had been a little bit acquainted of this your broadcast offered bright clear idea

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEnglish