Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How To Pass Environment variables in Compose ( docker compose )

There are multiple parts of Compose that deal with environment variables in one sense or another. So how do I pass Environment variables in Compose ( docker-compose )

According to the documentation If you have multiple environment variables, you can substitute them by adding them to a default environment variable file named .env or by providing a path to your environment variables file using the –env-file command line option.

version: '3.9'
services:
  nginx:
    image: nginx:stable-alpine
    container_name: nginx
    ports:
      - 80:80
      - 443:443
    restart: always
    volumes:
        - ./nginx/nginx.conf:/etc/nginx/nginx.conf
  postgres:
    container_name: postgres
    image: postgres:13-alpine
    environment:
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=${DB_DATABASE}
    volumes:
      - ./pgdata:/var/lib/postgresql/data
      - ./database/app.sql:/docker-entrypoint-initdb.d/app.sql
    restart: always
    ports:
      - "35000:5432"
    networks:
      - app_network

  app-api:
    container_name: app-api
    build:
      dockerfile: Dockerfile
      context: ./app-api
      target: production
    environment:
      - DB_TYPE=${DATABASE_TYPE}
      - POSTGRES_HOST=${DB_HOST}
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASS=${DB_PASSWORD}
      - POSTGRES_DB=${DB_DATABASE}
      - POSTGRES_PORT=${DB_PORT}
      - APP_PORT=${SERVER_PORT}
      - NODE_ENV:production

      ## AWS
      - AWS_S3_ACCESS_KEY=${AWS_S3_ACCESS_KEY}
      - AWS_S3_SECRET_ACCESS_KEY=${AWS_S3_SECRET_ACCESS_KEY}
      - AWS_S3_BUCKET=${AWS_S3_BUCKET}
      - AWS_S3_REGION=${AWS_S3_REGION}
    ports:
      - "5050:80"
    volumes: 
      - ./pgadmin-data:/var/lib/pgadmin
    depends_on: 
      - postgres
    links:
      - postgres
    networks:
      - app_network

  pgadmin:
    container_name: pgadmin
    image: dpage/pgadmin4
    restart: always
    environment:
      - PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}
      - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}
      - PGADMIN_LISTEN_PORT=${PGADMIN_LISTEN_PORT}
    restart: always
    ports:
      - "5400:5400"
    depends_on:
      - postgres
    links:
      - postgres
    networks:
      - app_network

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you can use it like this. you have to pass value in each environment variable.

server:
    environment:
      - AWS_S3_ACCESS_KEY=ABCJQHWEQJHWQ
      - AWS_S3_SECRET_ACCESS_KEY=ASKJHDAKJHNAWKLHEN
      - AWS_S3_BUCKET=abc-text
      - AWS_S3_REGION=eu-west-1
    ports:
      - "5050:80"
    volumes: 
      - ./pgadmin-data:/var/lib/pgadmin
    depends_on: 
      - postgres
    links:
      - postgres
    networks:
      - app_network
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading