Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print the final version of `docker-compose.yml` with .env variables replaced?

I have a docker-compose.yml file which uses a few variables set in an .env file.

Is there an easy way to print the final version of the file, to check if everything was correctly replaced?

# .env
UBUNTU_VERSION=19.8

.

# docker-compose.yml

version: '3'

services:
  myservice:
    image: ubuntu:${UBUNTU_VERSION}
    env-file:
      - .env

Note:

Compose supports declaring default environment variables in an environment file named .env placed in the folder where the docker-compose

Documentation: https://docs.docker.com/compose/env-file/

like image 278
Roberto Morávia Avatar asked Dec 14 '25 21:12

Roberto Morávia


1 Answers

Given the following files:

# docker-compose.yml

version: '3'
services:
  myservice:
    image: ubuntu:${UBUNTU_VERSION}
    env-file:
      - .env
# .env

UBUNTU_VERSION=20.01

You can run

docker-compose config

And you'll get the formatted config file out:

❯ docker-compose config
services:
  myservice:
    environment:
      UBUNTU_VERSION: '19.8'
    image: ubuntu:19.8
version: '3'
like image 143
TylerLubeck Avatar answered Dec 16 '25 12:12

TylerLubeck