How do you define a default value in Docker Compose interpolation?

Experience Level: Senior
Tags: Docker Compose


Use the following syntax with default value after dash:

version: "3.9"
    image: "postgres:${POSTGRES_VERSION:-1.0.0}"

If the environment variable POSTGRES_VERSION is not defined, the image version will fall back to postgres:1.0.0.


No Comments Yet.
Be the first to tell us what you think.
Docker Compose
Docker Compose

Are you learning Docker Compose ? Try our test we designed to help you progress faster.

Test yourself