error: unexpected end of file (expecting “do”) for shell script in Dockerfile

I don’t want to have another .sh file with a script and going to add a shell script code promptly in the Dockerfile. However, I receive an error message during the image build:

/bin/sh: syntax error: unexpected end of file (expecting “do”)

  • Which is the best way to pass AWS credentials to Docker container?
  • Kubernetes MySQL replication - Master service host inquiry
  • Can't resolve hostnames between docker containers
  • Docker does not want to install vim into my container image
  • Using docker-compose to collaborate on existing git repo Django project
  • Add windows folder in Dockerfile
  • Here is the part of the Dockerfile with a script:

    RUN cat .env | while [ read LINE ] \
    do \
        envName=$(echo "$LINE" | grep -o "^[^\=]*") \
        echo "PassEnv $envName" >> httpd.conf \
    done
    

    Any ideas what is wrong?

  • Docker mount a volume as root
  • Docker: Could not read CA certificate: no such file or directory
  • Cannot get image on Docker - Network timed out [Windows]
  • redis+elk stack using docker-compose
  • Go imageproxy inaccessible from docker container
  • Is docker an ephemeral instance?
  • 2 Solutions collect form web for “error: unexpected end of file (expecting “do”) for shell script in Dockerfile”

    Remove de square brackets [], and use ; at end of lines because docker join lines when see your \‘s, so the commands get melt.

    This is working for me:

    RUN cat .env | while read LINE ;\
        do \
          envName=$(echo "$LINE" | grep -o "^[^\=]*"); \
          echo "PassEnv $envName" >> httpd.conf ;\
        done
    

    The while construct expects do to be on a separate line (or, to appear after a semicolon). So you probably want:

    RUN cat .env | while [ read LINE ]; \
    do \
        envName=$(echo "$LINE" | grep -o "^[^\=]*") \
        echo "PassEnv $envName" >> httpd.conf \
    done
    

    Note the semicolon on the first line.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.