How to echo environment variables in Docker

My docker-compose.yml is:

version: '2'

volumes:
  postgres_data: {}
  postgres_backup: {}

services:
  postgres:
    build: ./compose/postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - postgres_backup:/backups
    env_file: .env

  django:
    build:
      context: .
      dockerfile: ./compose/django/Dockerfile
    user: django
    depends_on:
      - postgres
      - redis
    command: /gunicorn.sh
    env_file: .env

  nginx:
    build: ./compose/nginx
    depends_on:
      - django

    ports:
      - "0.0.0.0:80:80"


  redis:
    image: redis:latest
    restart: always

And in my .env file, I have:

  • Unable to access Docker containers folder on command line
  • run a meteor app on docker - doesn't open in localhost
  • How to get Libsodium running on Alpine Java
  • Storing base java project inside child project jar (maven, docker)
  • Can't attach terminal to a running container in docker
  • Docker build just freezes?
  • # PostgreSQL
    POSTGRES_PASSWORD=mysecretpass
    POSTGRES_USER=postgresuser
    

    How do I test if the environment variables are effectively set?

    I’ve tried tu run on the remote machine:

    docker run sorbetcitron_django echo $POSTGRES_USER
    

    where sorbetcitron_django is my django image, but it outputs nothing.

  • Jhipster-Logstash does not start correctly
  • mariadb docker container on OS X: can't create database directory
  • Not able to run Meteor application in Docker container because of couldn't run ps ax error
  • Error: Cannot Start Container: stat /bin/sh: no such file or directory"
  • Can not connect to websocket using django-channels , nginx on docker as services
  • Is there a way to add a hostname to an EXISTING docker container ?
  • One Solution collect form web for “How to echo environment variables in Docker”

    I’d use:

    docker-compose run postgres env
    

    If you pass a $POSTGRES_USER to your cli, it’s going to get interpreted by the shell on the host, and if you escape the $, you’ll need to eval the line to get the shell to parse the $ inside the container.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.