Alias service environment var in a Docker container

I use Docker Compose to spin up my containers. I have a RethinkDB service container that exposes (amongst others) the host port in the following env var: APP_RETHINKDB_1_PORT_28015_TCP_ADDR.

However, my app must receive this host as an env var named RETHINKDB_HOST.

  • Freegeoip with Docker Cloud
  • Some questions of Docker -p and Dockerfile
  • Error response from daemon: Get https://x.x.x.x/v1/users/: x509: certificate signed by unknown authority
  • Trying to run Cloudera Image in Docker
  • How to set up a simple docker-contained reverse-proxying (nginx) server?
  • can't acces mongo from inside docker
  • My question is: how can I alias the given env var to the desired one when starting the container (preferably in the most Dockerish way)? I tried:

    env_file: .env

    but first, it doesn’t work and second, it doesn’t look as if it’s the best way to go.

  • DOCKER | docker-compose create and deploy image to
  • Set Docker_Opts in centos
  • Windows Containers - culture settings
  • Can not reach HTTP servlet when built as Dockercontainer
  • Python dependency issues with Django on Docker
  • docker with shared folder d drive
  • 2 Solutions collect form web for “Alias service environment var in a Docker container”

    When one container is linked to another, it sets the environment variable, but also a host entry. For example,


    will allow ubuntu to ping rethinkdb and have it resolve the IP address. This would allow you to set RETHINKDB_HOST=rethinkdb. This won’t work if you are relying on that variable for the port, however, but that’s the only thing I can think of besides adding a startup script or modifying your CMD.

    If you want to modify your CMD, which is currently set to command: service rethink start, for example, just change it to prepend the variable assignment, e.g.

    command: sh -c 'RETHINKDB_HOST=$APP_RETHINKDB_1_PORT_28015_TCP_ADDR && service rethink start'

    The approach would be similar if you are using a startup script, you would just add that variable assignment as a line before the service starts

    The environment variable name APP_RETHINKDB_1_PORT_28015_TCP_ADDR you are trying to use already contains the port number. It is already kind of “hard coded”. I think you simply have to use this

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