0

To run my project, I use the command docker-compose up --build -d my container starts and stops immediately. In the container details I have this :

2023-03-09 12:50:46 questionnaire-front-survey_dev-1 | /bin/sh: ./env.sh: not found

I'm not sure if that's relevant but I have this in my dockerfile : CMD ./env.sh > ./public/env.js && yarn start

And this is my env.sh file :

#!/bin/sh

# Add assignment 
echo "window._ENV_ = {"

# Get all env variables
# Read each line in env
# Each line represents key=value pairs
printenv | grep REACT_APP* | while read -r line || [ -n "$line" ];
do
  # Split env variables by character `=`
  if printf '%s\n' "$line" | grep -q -e '='; then
    varname=$(printf '%s\n' "$line" | sed -e 's/=.*//')
    varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//')
  fi

  # Append configuration property to JS file
  echo "  $varname: \"$varvalue\","
  
done

echo "}"

I have no idea why I have this error.

Thank you!

I've checked, all my files are in CRLF. And I'm on windows.

  • Make sure your env.sh file and docker-compose file are in same folder – Elvin Jafarov Mar 09 '23 at 13:11
  • You should append Dockerfile and probably docker-compose.yml as well. – JeffRSon Mar 09 '23 at 13:12
  • 1
    If your files _do_ have Windows-style CRLF line endings, then they will not run in Linux containers, with exactly the sort of "not found" error you're seeing (the script interpreter from the shebang line will be `/bin/sh\r`). Convert it to Unix-style LF-only line endings. Also see for example [Are shell scripts sensitive to encoding and line endings?](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings) – David Maze Mar 09 '23 at 13:45

0 Answers0