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

Can't connect to server after using docker run #3165

Open
cthulu opened this issue Mar 5, 2019 · 12 comments
Open

Can't connect to server after using docker run #3165

cthulu opened this issue Mar 5, 2019 · 12 comments
Labels
documentation Developer and end-user documentation self-hosting Discussion, problems, features, and documentation related to self-hosting Shields

Comments

@cthulu
Copy link

cthulu commented Mar 5, 2019

🪲 Description

I'm following the instructions in doc/self-hosting.md to first build the Docker image (which works fine) and then run the container using docker run --rm -p 8080:80 --name shields shields.

It looks like the container hangs forever:

$ docker run --rm -p 8080:80 --name shields shields
raven@2.6.4 alert: no DSN provided, error reporting disabled
Configuration:
{ bind: { address: 'localhost' },
  metrics: { prometheus: { enabled: false } },
  ssl: { isSecure: false },
  cors: { allowedOrigin: [ 'http://localhost:3000' ] },
  persistence: { dir: './private' },
  services:
   { github:
      { baseUri: 'https://api.github.com/',
        debug: { enabled: false, intervalSeconds: 200 } },
     trace: false },
  profiling: { makeBadge: false },
  cacheHeaders: { defaultCacheLengthSeconds: 120 },
  rateLimit: false,
  handleInternalErrors: false,
  fetchLimit: '10MB' }
0305092655 FsTokenPersistence configured with /usr/src/app/private/github-user-tokens.json
0305092655 Server is starting up: http://localhost/

I think it expects a response from Gatsby or something (I'm not a Node expert).

If I run the app manually using npm start it works, but I'd like to containerize it.

@cthulu cthulu mentioned this issue Mar 5, 2019
3 tasks
@calebcartwright calebcartwright added the self-hosting Discussion, problems, features, and documentation related to self-hosting Shields label Mar 5, 2019
@paulmelnikow
Copy link
Member

What is the expected behavior?

@calebcartwright
Copy link
Member

I haven't checked today, but my scheduled job successfully built the image and then ran it on Friday March 1st. That was with commit 56e71d7

@cthulu
Copy link
Author

cthulu commented Mar 6, 2019

@paulmelnikow the expected behavior is that http://localhost:8080 will be exposing port :80 of the container and having shields running. However I get connection refused as the container starts but the application startup never finishes - I even have to manually kill the container docker kill shields.

I have no issues with running any other containers (docker engine 18.0.9.2, Mac).

When running the npm start (not in Docker, just locally), the startup continues:

[server] 0306104015 Server is starting up: http://localhost:8080/
success open and validate gatsby-configs — 0.008 s

In container I'm stuck on the line 0306104216 Server is starting up: http://localhost/

@cthulu
Copy link
Author

cthulu commented Mar 6, 2019

I've tried also 56e71d7 with the same result.

Maybe the problem is the CMD node server. Shouldn't it be npm start?

@paulmelnikow
Copy link
Member

npm start runs two processes, one of which is the Gatsby development server. In production you don't need the Gatsby server; instead the Dockerfile triggers a static build which does not need to be run in production. This gets served by the same node process that handles the badges.

I think the process inside the container needs to bind to all interfaces instead localhost. If that isn't the issue, then the port is wrong. Maybe it's supposed to be -p 80:8080 instead of -p 8080:80?

It would be helpful to document all this in self-hosting.md – would definitely welcome contributions there!

@paulmelnikow paulmelnikow changed the title docker run does hangs forever Can't connect to server after using docker run Mar 7, 2019
paulmelnikow added a commit that referenced this issue Mar 7, 2019
1. Set NODE_ENV=production in Docker.
2. When NODE_ENV is production, bind to all interfaces. This seems like a
   sensible default.
3. Exclude Dockerfile from container to improve layer cacheability when
   modifying the dockerfile.

Ref #3165
@paulmelnikow
Copy link
Member

I'm guessing the only way the Dockerfile works today is by to pass an alternative command to run, like node server 80 0.0.0.0. I opened #3173 so it defaults to using 0.0.0.0 (all interfaces) in production, and set NODE_ENV=production in the Dockerfile, which should make the default command usable.

The reason the process isn't receiving a signal is that you need docker run --init, which tells Docker to runs the entrypoint inside a subprocess that properly handles signals. This has the added benefit of speeding up shutdown when using docker stop.

It would be great to document which CLI arguments are commended. I'm not sure what docker --rm does or whether --name shields should be in there, though I have gotten things working by using the changes from #3173 with docker run -p 8080:80 WHATEVER_IMAGE_ID.

@calebcartwright
Copy link
Member

rm does some clean up stuff when the container's stopped if i recall correctly.

I'm personally running a docker run -d ... with the image, but I'm also passing in a lot of environment variable args to the container, including the bind address which I suspect is why mine was still working

@paulmelnikow
Copy link
Member

Ah, right, I forgot you could set the bind through the env. Seems good to have it an entrypoint that works by default!

rm does some clean up stuff when the container's stopped if i recall correctly.

Sounds worth including then. 👍

calebcartwright pushed a commit that referenced this issue Mar 7, 2019
* Tweak Docker initialization

1. Set NODE_ENV=production in Docker.
2. When NODE_ENV is production, bind to all interfaces. This seems like a
   sensible default.
3. Exclude Dockerfile from container to improve layer cacheability when
   modifying the dockerfile.

Ref #3165

* Rm obsolete comment
@calebcartwright
Copy link
Member

using the latest Dockerfile from master, I'm able to build the image, and run the container (on Ubuntu 18.04) successfully (the only environment variables I'm passing to the container are tokens/credentials for various badge services)

@paulmelnikow paulmelnikow added the documentation Developer and end-user documentation label Mar 7, 2019
@paulmelnikow
Copy link
Member

Would welcome a PR for the docs! Let's leave this open until that's taken care of.

@cthulu
Copy link
Author

cthulu commented Mar 7, 2019

I can confirm, it's working now. Great work and thanks!

@calebcartwright
Copy link
Member

@paulmelnikow - what's in scope for the doc updates? The self-hosting doc section for docker currently shows:

$ docker run --rm -p 8080:80 --name shields shields
# or if you have shields.env file, run the following instead
$ docker run --rm -p 8080:80 --env-file shields.env --name shields shields

So are you thinking the doc should include details/descriptions about the args shown (port mapping, clean up, etc.) and/or why the guide suggests those?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Developer and end-user documentation self-hosting Discussion, problems, features, and documentation related to self-hosting Shields
Projects
None yet
Development

No branches or pull requests

3 participants