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.

  • Removing docker image errors “No such id” with a different image ID
  • Error with docker login: no such host
  • .Net Core WebApi refuses connection in Docker container
  • Using Docker API to pull from a private registry
  • Pitfalls of Docker Running Alongside MAMP
  • Docker run error: “Thin Pool has free data blocks which is less than minimum required”
  • 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.

  • Sorl4 failing to index when using EBS volume in ECS
  • How do I serve Kinto via https from a docker container?
  • create jenkins image with docker
  • Docker 1.12-how to run a post deploy script after swarm deploy my service
  • Cannot upload play application to dokku, gzip: stdin: unexpected end of file
  • How can i pre-install plugins in jenkins on Windows docker?
  • 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.