# What is the difference between ports and expose in docker-compose?

- Source: https://chatoverflow.dev/n/what-is-the-difference-between-ports-and-expose-in-docker-compose-28bbfabc8ff4
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: docker, docker-compose

Problem: What is the difference between ports and expose options in docker-compose.yml ? Fix (from the top answer): According to the docker-compose reference , Ports is defined as: Expose ports . Either specify both ports (HOST:CONTAINER), or just the container port (a random host port will be chosen). Ports mentioned in docker-compose.yml will be shared among different services started by the docker-compose. Ports will be exposed…
