0

The Dockerfile contains:

ENV VAR 1
COPY ./setup.exp /tmp/
RUN chmod a+x /tmp/setup.exp

The expect file:

#!/usr/bin/expect
set timeout -1
spawn setup -v
expect "Enter variable: "
send -- "$env(VAR)\r"

The shell file (main.sh):

#!/bin/sh
/tmp/setup.exp $VAR

When I run ./main.sh from the shell inside the container, it works perfectly fine.

However, when I run docker-compose up with entrypoint: ./main.sh, it prints this error:

send: spawn id exp4 not open
    while executing
"send -- "$env(VAR)\r""
    (file "/tmp/setup.exp" line 5)

If I pass the variable directly as entrypoint: /tmp/setup.exp ${VAR}, it prints this warning:

WARNING: The VAR variable is not set. Defaulting to a blank string.

I also tried set VAR [lindex $argv 0]; and then send -- "$VAR\r" without any success.

Seems like from inside the container the script is able to load docker's env variables.

Any suggestions?

user13581602
  • 105
  • 1
  • 9
  • 1
    "spawn id exp4 not open" means the setup program has already exited. – glenn jackman Feb 16 '21 at 02:39
  • That warning `The VAR variable has not been set` means you need to set that environment variable in your current shell environment before running docker-compose. Can you try `export VAR=1` and then re-running `docker-compose up`? – cam Feb 16 '21 at 03:38
  • As I understand it, the syntax is `ENV VAR 1`. – meuh Feb 16 '21 at 10:12
  • Yes you are right @meuh the syntax I posted is actually for docker-compose `environment: - VAR=1` – user13581602 Feb 16 '21 at 10:50

1 Answers1

0

Thanks @glennjackman for pointing that out. I ran expect -d for a more verbose output.

It turns out the reason the program exited is because python was raising this exception:

ValueError: invalid width 0 (must be > 0)

Setting the variable say ENV COLUMNS 100 in the Dockerfile solved the issue for me.

user13581602
  • 105
  • 1
  • 9