Docker Community Forums

Share and learn in the Docker community.

Dockerfile in GitLab using .sh scripts that prompt for user input

Hello,

I am trying to run a dockerfile using linux in gitlab for automatic build and learning purposes. I’m not sure how it works when trying to use a script shell file that pauses and waits for input at the command line multiple times. Is there any command to automatically send the desired inputs?

Currently when I am running the .sh file I get the following error (it is looping here):
Do you agree to the above terms and conditions? unrecognised response: ‘’

Please answer with one of: ‘yes’ or ‘no/quit’


I have run docker locally using interactive mode and this has gone well, but now it gets confusing when everything should happen automatically.

Best Regards.

Can you use a Bash pipe, like some RUN echo "yes" | script.sh?

I am not sure, I tried the command you suggested, but it never gets past the previous RUN command.

What do you mean with “previous” in “previous RUN command”? Maybe show us the Dockerfile?

This is the docker file below. What I am doing is copying a tar file into the docker container and extracting it. There will be some files, and I want run one of them which is a .sh file (setup.sh). This will install some compiler that will be used. This .sh file will pause and ask for inputs multiple times, like install directory, reading through terms etc.

The build will get stuck at RUN /tmp/Test/Installer/setup.sh.
This line will never run at all: RUN echo “yes” | setup.sh

FROM centos
COPY ./Files /tmp/Test/
RUN cd /tmp/Test/ && tar -xvf DS500-PA-00003-r5p0-25rel0.tgz
RUN /tmp/Test/Installer/setup.sh
RUN echo "yes" | setup.sh

Any ideas? Thanks.

Ah, sure the 2nd RUN would still await the input, and the 3rd RUN doesn’t make much sense if the 2nd one would have completed. I’d try:

RUN echo "yes" | /tmp/Test/Installer/setup.sh

To handle the multiple inputs that the script expects, see shell - How send multiple command as input in a program? - Unix & Linux Stack Exchange.

Aside, I’ve edited your post; Markdown fenced code blocks are your friend in the forum to keep things readable:

```text
FROM ...
COPY ...
RUN ...
```

Did you mean to replace the 2nd and 3rd RUN with the line you suggested?

Unfortunately, it didn’t work. It is still stuck in the loop and “yes” doesn’t get printed or input at all.

In order to build a container of something, you need to automate the whole configuration and installation process. You might want to ask the maintainer of the setup.sh to introduce a parameter or flag for a batch installation (as in non-interactive) that either performas an installation with default parameters or accepts a config file.

From my perspective this is rather a “how do I perform an unatended setup for this application” than a real docker problem…

Ok, got it. Thanks for the replies.

Also, if you cannot have the install script changed to allow for silent installation, then see the link to Stack Exchange that I posted earlier, for other options to pass input(s). For that too, you should be able to use that without Docker before trying to include it in your Dockerfile (or create another shell script to pass the user input, and RUN that script).