D
D
Dmitry Evgrafovich2017-06-18 04:19:04
Docker
Dmitry Evgrafovich, 2017-06-18 04:19:04

How to write a host's ip to a variable for another host in docker-compose?

There are several containers for the laravel application and a container with an smtp service, all of which is located behind nginx-proxy. The task is to pass the ip address of the smtp service as a variable to containers with laravel, previously there was a variable name_PORT_num_protocol_ADDR for this.
Contents of docker-compose.yml:

version: "3"
services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./Docker/Nginx:/etc/nginx/vhost.d:ro
  db:
      image: mysql:5.7
      container_name: db
      environment:
          MYSQL_DATABASE: dbname
          MYSQL_USER: user
          MYSQL_PASSWORD: pass
          MYSQL_ROOT_PASSWORD: pass
      volumes:
             - ./db_data:/var/lib/mysql
      restart: always
      ports:
        - "3306:3306"

  smtp:
    image: weave/rest-smtp-sink
    container_name: smtp
    ports:
       - "25:25"
    expose:
       - 80
    environment:
      VIRTUAL_HOST: mail.dockerexample.ru

  app:
      links:
        - smtp
      depends_on:
        - db
        - smtp
      image: hitalos/laravel
      container_name: app
      environment:
        SMTP_HOST: ??? - вот тут нужен адрес
        VIRTUAL_HOST: dockerexample.ru
        DB_HOST: db
        DB_DATABASE: dbname
        DB_USERNAME: user
        DB_PASSWORD: pass
        DB_CONNECTION: mysql
      expose:
        - 80
      volumes:
        - ./:/var/www/

volumes:
  db_data:
networks:
  default:
    external:
      name: nginx-proxy

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question