Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Container Won't Start #42

Closed
quistuipater opened this issue Sep 18, 2020 · 6 comments
Closed

Docker Container Won't Start #42

quistuipater opened this issue Sep 18, 2020 · 6 comments

Comments

@quistuipater
Copy link

quistuipater commented Sep 18, 2020

I'm trying to run Owntracks Frontend (owntracks/frontend:latest) in a Docker container via Portainer and the command to start it is:

/bin/sh -c /bin/sh -c " envsubst \${SERVER_HOST} \${SERVER_PORT} \${LISTEN_PORT} < /etc/nginx/nginx.tmpl > /etc/nginx/nginx.conf && nginx -g daemon off; || ( env; cat /etc/nginx/nginx.conf ) "

The environment vars are:

SERVER_HOST 192.168.2.232
SERVER_PORT 80
PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
NGINX_VERSION 1.17.10
NJS_VERSION 0.3.9
PKG_RELEASE 1
LISTEN_PORT 80

Unfortunately, the container starts and stops immediately reporting:

\${SERVER_PORT}: line 1: syntax error: unterminated quoted string

I've poked around trying to fix this for way too long. What am I missing?

@linusg
Copy link
Member

linusg commented Sep 18, 2020

Do not specify a command for starting manually, the Dockerfile has a CMD entry. That's enough, even for Portainer - I just tested it. Just set the env variables and you're good to go.

Also, the command provided by you is missing some quotation marks.

@linusg linusg closed this as completed Sep 18, 2020
@quistuipater
Copy link
Author

The command I quoted is what's in the CMD entry as displayed in Portainer's "Container Details" section. Under "Duplicate/Edit" it shows CMD as:

'/bin/sh' '-c' '/bin/sh' '-c' ' envsubst \${SERVER_HOST} \${SERVER_PORT} \${LISTEN_PORT} < /etc/nginx/nginx.tmpl > /etc/nginx/nginx.conf && nginx -g daemon off; || ( env; cat /etc/nginx/nginx.conf ) '

The only change I made to the default configuration is to specify a macvlan as the network otherwise the configuration is as the original container.

@linusg
Copy link
Member

linusg commented Sep 18, 2020

Again, it worked for me. If you insist to a) do it this way and not, let's say, docker-compose and b) it's still not working I'll need step-by-step instructions to reproduce :)

@quistuipater
Copy link
Author

Here's what I did ...

  1. Portainer > Create Container
  2. Image: owntracks/frontend:latest
  3. Changed Network to my macvlan
  4. Set IPv4 address to 192.168.3.100
  5. Set Primary DNS to 192.168.2.112 (that's a Pi-Hole container)
  6. Set Secondary DNS to 8.8.8.8
  7. Set Env > SERVER_HOST to 192.168.2.103 (that's a Mosquitto container)
  8. Deployed successfully then the container immediately stops
  9. Log shows \${SERVER_PORT}: line 1: syntax error: unterminated quoted string

Is the problem caused by using an IP address for SERVER_HOST rather than a host name?

@linusg
Copy link
Member

linusg commented Sep 18, 2020

Thank you. I could reproduce the error now - after editing the existing container created by Portainer, it seems to change the command for some reason, possibly messing up the quotes?!

Either way, please try this:

  • Click on "Duplicate/Edit"

  • Replace the command (now with a lot more quotes than necessary 👀) with this:

    /bin/sh -c "envsubst '\${SERVER_HOST} \${SERVER_PORT} \${LISTEN_PORT}' < /etc/nginx/nginx.tmpl > /etc/nginx/nginx.conf && nginx -g 'daemon off;' || ( env; cat /etc/nginx/nginx.conf )"
    
  • When asked to replace the container, confirm

  • In my case it was running again afterwards, could be stopped and started again

The Portainer UI now shows this command in my case on the container overview page, which is wrong again (missing some quotes):

/bin/sh -c envsubst '\${SERVER_HOST} \${SERVER_PORT} \${LISTEN_PORT}' < /etc/nginx/nginx.tmpl > /etc/nginx/nginx.conf && nginx -g 'daemon off;' || ( env; cat /etc/nginx/nginx.conf )

and when I edit the container, this (even more wrong):

'/bin/sh' '-c' 'envsubst '\${SERVER_HOST} \${SERVER_PORT} \${LISTEN_PORT}' < /etc/nginx/nginx.tmpl > /etc/nginx/nginx.conf && nginx -g 'daemon off;' || ( env; cat /etc/nginx/nginx.conf ) '

It seems like I would have to repeat this step (update the command) every time I make some edits to the container, which is annoying (and possibly a bug in Portainer). Anyway, please try if this works for you!

@quistuipater
Copy link
Author

Yes! It now works fine. As a workaround I might try to put the command in an Env variable then use the variable in the CMD.

Thanks for the quick response. And congratulations on creating a terrific application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants