1

I need to read a bunch of environmental variables from a text file which exists in a docker image at address (/service/variables.txt) and set them as environmental variables in my running container and then execute a command which utilized them. I'm doing these steps in a docker-compose file as follows. I'd like my docker-compose to look like something like below.

services:
  service1:
    image: imagename:tag
    container_name: name
    command:
         - exec source /service/variables.txt
         - exec export $(cut -d= -f1 /service/variables.txt)
         - exec start_service $VAR1 $VAR2

My question is how can I have multiple exec command under command in a docker-file?

HHH
  • 6,085
  • 20
  • 92
  • 164
  • Is wrapping commands in a script an option for you? – leopal Aug 30 '19 at 14:07
  • 1
    You can wrap it into a shell script and run it as an ENTRYPOINT of a docker image. – Toan Quoc Ho Aug 30 '19 at 14:13
  • 2
    Possible duplicate of [Using Docker-Compose, how to execute multiple commands](https://stackoverflow.com/questions/30063907/using-docker-compose-how-to-execute-multiple-commands) – David Maze Aug 30 '19 at 14:14
  • So the script should be in a separate file and I include all 3 commands in there? – HHH Aug 30 '19 at 14:41
  • I put those commands in a script file (script.sh) which exist in the same directory as my docker-compose .yaml file but when running the docker-compose it says the script.sh does not exist, "stat source ./script.sh: no such file or directory" – HHH Aug 30 '19 at 15:12
  • @H.Z. You should copy script file during image build so it is available at runtime. – leopal Sep 02 '19 at 05:20

0 Answers0