0

I am using following command in docker-compose to copy environment values into nginx configuration file at startup of nginx container.

command: /bin/sh -c "envsubst < /etc/nginx/conf.d/site.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"

I want to get rid of docker-compose and use it with the docker run. I tried to inlcude the command in Dockerfile and use CMD. But the ngix container immediately exit.

FROM mydocker:latest
COPY ./site.template /etc/nginx/conf.d/site.template

CMD envsubst < /etc/nginx/conf.d/site.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'

Can someone please help me here. Thanks in advance

Daybreaker
  • 1,037
  • 5
  • 20
  • 42
  • 1
    So why not `CMD /bin/sh -c "envsubst < /etc/nginx/conf.d/site.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"`? What is your entrypoint? – KamilCuk May 21 '20 at 10:48
  • 1
    [This answer](https://stackoverflow.com/a/56651109/10008173) shows an entrypoint-oriented approach to the same problem; it's a little more focused on a Compose-only setup but it's pretty easy to translate that to Dockerfile syntax. – David Maze May 21 '20 at 10:56
  • @DavidMaze thanks mate. I that answer helped and it works now. thanks you too. – Daybreaker May 21 '20 at 11:59

0 Answers0