Member-only story

File Structure of docker-compose.yml File

Meghasharmaa

The structure of a docker-compose.yml file typically follows a hierarchical format using YAML syntax. Here's a breakdown of the common sections and their respective components:

  1. Version: This is the version of the Docker Compose file format you’re using. It’s typically at the top of the file and specifies which features and syntax are available for use.

For example:

version: '3.8'

2. Services: This section defines the various services or containers that make up your application. Each service is listed under the services keyword and has its own configuration.

Here's an example:

services:
web:
image: nginx:latest
ports:
- "8080:80"
database:
image: postgres:latest
environment:
POSTGRES_USER: myuser
POSTGRES_PASSWORD: mypassword

3. Networks: This section allows you to define custom networks for your services. Networks enable containers to communicate with each other over isolated networks. You can specify network configurations such as aliases, IP addresses, and external connectivity.

For example:

networks:
my_network:
driver: bridge

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Responses (2)

Write a response

Thanks for providing such a great explanation about structure of docker-compose file

6

This is exactly what I was looking for about a month ago getting started with Docker. Thank you! Only complaint I wish you wrote it 2 months ago.

1