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?
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.