0

I want to pass an env/build var to my Dockerfile for use in its entryxoint and thought I could do it from the docker-compose file like so

  web:
    restart: "no"
    build:
      context: ../my-project
      args:
        CURRENT_ENV: "development"

In my Dockerfile, I have this defined

ARG CURRENT_ENV
ENTRYPOINT /bin/sh -c "rm -f /app/tmp/pids/*.pid && [[ $CURRENT_ENV = 'dev' ]] && /usr/local/rbenv/versions/`cat .ruby-version`/gemsets/my-project/bin/foreman start -f Procfile || /usr/local/rbenv/versions/`cat .ruby-version`/gemsets/my-project/bin/foreman start -f Procfile.hot; tail -f /dev/null"

However when I start my containers using “docker-compose up”, it doesn’t appear the entry point is picking up the variable as it has a empty string before the “= ‘dev’” section …

myco-deploy-web-1    | /bin/sh: -c: line 0: `rm -f /app/tmp/pids/*.pid && [[  = 'dev' ]] && /usr/local/rbenv/versions/2.4.5/gemsets/my-project/bin/foreman start -f Procfile || /usr/local/rbenv/versions/2.4.5/gemsets/my-project/bin/foreman start -f Procfile.hot; tail -f /dev/null'

What’s the proper way to pass the build arg/env var to my ENTRYPOINT command?

Dave
  • 15,639
  • 133
  • 442
  • 830
  • (Consider writing this as a shell script rather than a complex inline command, and at the Compose level overriding the container's `command:` rather than trying to build a special dev-only image.) – David Maze Jun 15 '22 at 17:29

1 Answers1

0

The ENTRYPOINT needs the variable to be an environment variable rather than a build arg.

You can do this

ARG CURRENT_ENV
ENV CURRENT_ENV $CURRENT_ENV
ENTRYPOINT /bin/sh -c "rm -f /app/tmp/pids/*.pid && [[ $CURRENT_ENV = 'dev' ]] && /usr/local/rbenv/versions/`cat .ruby-version`/gemsets/my-project/bin/foreman start -f Procfile || /usr/local/rbenv/versions/`cat .ruby-version`/gemsets/my-project/bin/foreman start -f Procfile.hot; tail -f /dev/null"

and it should work

Hans Kilian
  • 18,948
  • 1
  • 26
  • 35