3

I have docker-compose.yml as follows:

version: '2'

services:
  eureka-server:
    image: some-dtr-name/some-orgname/some-reponame:some-versionname
    mem_limit: somememory
    environment:
      SPRING_PROFILES_ACTIVE: some-profile
      JAVA_OPTS: -Xms256m -Xmx512m
    ports:
    - "some-port:some-port"
    restart: always
    networks:
    - cloud

networks:
  cloud:
   driver: bridge

I want to pass some-dtr-name,some-orgname,some-reponame,some-versionname,somememory,some-profile,some-profile,some-port as a aurgument to docker-compose file. I am doing this task using shell file.

#!/bin/bash
some-dtr-name="$1"
some-orgname="$2"
some-reponame="$3"
some-versionname="$4"
somememory="$5"
some-profile="$6"
some-profile="$7"
some-port="$8"

docker-compose up

How can I do this task ??

zeppelin
  • 8,947
  • 2
  • 24
  • 30

1 Answers1

0

Docker compose supports the environment variable substitution, using the ${} syntax: https://docs.docker.com/compose/compose-file/#variable-substitution

So if you have the environment variable some_port defined, before you run docker-compose, you can then just refer to it as ${some_port} in your docker-compose file.

ports:
- "${some_port}:${some_port}"

Another thing to note is that the variable names in your sample code contain dashes -, which is not valid in bash

name A word consisting only of alphanumeric characters and underscores, and beginning with an alphabetic character or an underscore. Also referred to as an identifier.

you have to use underscore character _ instead.

zeppelin
  • 8,947
  • 2
  • 24
  • 30