Docker Compose - command using the container environment variable

Using Docker Compose to bind the master and slave services together. Thus, the slave container is automatically entered through Compose with environment variables containing the various ports and IP addresses needed to connect to another master container.

The service accepts the IP / port of the wizard using the command line argument, so I set it to mine commands.

master:
  command: myservice
  ports:
    - '29015'
slave:
  command: myservice --master ${MASTER_PORT_29015_TCP_ADDR}:${MASTER_PORT_29015_TCP_PORT}
  links:
    - master:master

The problem is that environment variables, such as those MASTER_PORT_29015_TCP_PORT, are computed when the build command is executed, and not from the container itself, where they are actually set.

When you start the cluster, you see a warning: WARNING: The MASTER_PORT_29015_TCP_ADDR variable is not set. Defaulting to a blank string.

entrypoint: ["/bin/sh", "-c"], , . ( , RethinkDB).

+4
1

, , master $MASTER_PORT_29015_TCP_ADDR. , , $MASTER_PORT_29015_TCP_PORT, , 29015.

, :

myservice --master master:29015
+2

Source: https://habr.com/ru/post/1621977/


All Articles