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”)

  • docker - how can we export/import (or save/load) only the new changes?
  • Updating boot2docker to 1.4.0 not taking
  • How to solve Docker permission error when trigger by Jenkins
  • Docker: setup proxy to download images
  • Is it possible to restrict access to lxc containers?
  • Docker losing volume bind mount
  • 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?

  • Copy files inside of docker image during build
  • how to set file and dir permissions on docker when developing
  • How to setup learning environment for Udacity Deep Learning class with TensorFlow (Windows)
  • Dynamically serving django docker containers
  • docker API delete container not working
  • Docker Build can't find pip
  • 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.