Search code examples
dockerenergyplus

Install EnergyPlus in. Docker Image


I am attempting to install EnergyPlus in a Docker Image, but getting stuck a the license acceptance during the docker build step?

My Dockerfile looks like:

FROM ubuntu:22.04

# wget
RUN apt-get update
RUN apt-get install -y wget 
RUN rm -rf /var/lib/apt/lists/*

# Download the EnergyPlus Install Script
RUN wget https://github.com/NREL/EnergyPlus/releases/download/v24.1.0/EnergyPlus-24.1.0-9d7789a3ac-Linux-Ubuntu22.04-x86_64.sh

# Make the EnergyPlus Install Script executable
RUN chmod +x EnergyPlus-24.1.0-9d7789a3ac-Linux-Ubuntu22.04-x86_64.sh

# Run the E+ Install Script
RUN export DEBIAN_FRONTEND=noninteractive
RUN ./EnergyPlus-24.1.0-9d7789a3ac-Linux-Ubuntu22.04-x86_64.sh

which all works, except that it gets hung up on the Do you accept the license? [y/N]: during the EnergyPlus installation.

I have reviewed the similar questions:

and have not found the answers there helpful in understanding how to solve my case here.

Is there a method for answering 'Y' during the Install? Note that after inputting 'Y', I then also have to enter 'Return' to confirm the default folder location as well? Is it possible to provide a series of different response values ("Y", "Return", ...) during the install like that?


Solution

  • Expect is a handy tool for handling interactive CLI applications.

    🗎 Dockerfile

    FROM ubuntu:22.04
    
    RUN apt-get update && \
        apt-get install -y \
            wget \
            expect \
            libgomp1 \
            libx11-6 && \ 
        rm -rf /var/lib/apt/lists/*
    
    RUN wget https://github.com/NREL/EnergyPlus/releases/download/v24.1.0/EnergyPlus-24.1.0-9d7789a3ac-Linux-Ubuntu22.04-x86_64.sh
    
    COPY install.exp .
    
    RUN chmod +x EnergyPlus-24.1.0-9d7789a3ac-Linux-Ubuntu22.04-x86_64.sh
    
    RUN expect install.exp
    
    CMD EnergyPlus -v
    

    You also need to install a couple of libraries to satisfy the dependencies of EnergyPlus. I have added those to the apt-get install command.

    The CMD is just to illustrate the the install was successful (see screenshot). You can obviously remove this.

    🗎 install.exp

    set timeout 120
    
    spawn ./EnergyPlus-24.1.0-9d7789a3ac-Linux-Ubuntu22.04-x86_64.sh
    
    expect -re {Do you accept the license.*:}
    send "y\r"
    
    expect -re {EnergyPlus install directory.*}
    send "\r"
    
    expect -re {Symbolic link location.*}
    send "\r"
    
    expect eof
    

    enter image description here