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

fix: Make sure the backend and front end are available before launching nginx #83

Merged
merged 1 commit into from
Jul 16, 2020

Conversation

arihantsurana
Copy link
Contributor

Currently this may in some cases cause nginx to fail at startup, with error:

nginx_1     | 2020/07/08 06:13:44 [emerg] 1#1: host not found in upstream "backend" in /etc/nginx/conf.d/default.conf:24
nginx_1     | nginx: [emerg] host not found in upstream "backend" in /etc/nginx/conf.d/default.conf:24

@Buuntu
Copy link
Owner

Buuntu commented Jul 8, 2020

Did you check that this actually made a difference? When I tried it it has the same net result. You still get the errors because even though the container is started, it's still building webpack.

Is it actually failing or is that just an error while the frontend boots up? Did it actually not load the site?

@inactivist
Copy link

inactivist commented Jul 15, 2020

Did you check that this actually made a difference? When I tried it it has the same net result. You still get the errors because even though the container is started, it's still building webpack.

Yeah, depends_on may not be completely reliable in some scenarios.

I've used the wait-for-it.sh bash script, or perhaps the docker-compose healthcheck feature is appropriate here (see also this)

Edit -- The docker-compose Control startup and shutdown order in Compose documentation recommends wait-for-it.sh :

Use a tool such as wait-for-it, dockerize, or sh-compatible wait-for. These are small wrapper scripts which you can include in your application’s image to poll a given host and port until it’s accepting TCP connections.
For example, to use wait-for-it.sh or wait-for to wrap your service’s command

See also upstream check in alpine version #173

@inactivist
Copy link

inactivist commented Jul 15, 2020

Is it actually failing or is that just an error while the frontend boots up? Did it actually not load the site?

In my experience, the nginx container exits and doesn't restart given current configuration, so it's a real problem.

$ docker-compose logs nginx
[extraneous log entries elided]
nginx_1     | 2020/07/15 12:26:37 [emerg] 1#1: host not found in upstream "backend" in /etc/nginx/conf.d/default.conf:20

$ docker-compose ps
              Name                             Command               State                       Ports                   
-------------------------------------------------------------------------------------------------------------------------
my-test-app_backend_1    python app/main.py               Up                                                  
my-test-app_flower_1     flower flower --broker=red ...   Up       0.0.0.0:5555->5555/tcp                     
my-test-app_frontend_1   /bin/bash /app/run.sh start      Up       35729/tcp, 8000/tcp
my-test-app_nginx_1      nginx -g daemon off;             Exit 1
my-test-app_postgres_1   docker-entrypoint.sh postgres    Up       0.0.0.0:5432->5432/tcp                     
my-test-app_redis_1      docker-entrypoint.sh redis ...   Up       0.0.0.0:6379->6379/tcp                     
my-test-app_worker_1     celery worker -A app.tasks ...   Up                                   

@Buuntu
Copy link
Owner

Buuntu commented Jul 15, 2020

Is it actually failing or is that just an error while the frontend boots up? Did it actually not load the site?

In my experience, the nginx container exits and doesn't restart given current configuration, so it's a real problem.

$ docker-compose logs nginx
[extraneous log entries elided]
nginx_1     | 2020/07/15 12:26:37 [emerg] 1#1: host not found in upstream "backend" in /etc/nginx/conf.d/default.conf:20

$ docker-compose ps
              Name                             Command               State                       Ports                   
-------------------------------------------------------------------------------------------------------------------------
my-test-app_backend_1    python app/main.py               Up                                                  
my-test-app_flower_1     flower flower --broker=red ...   Up       0.0.0.0:5555->5555/tcp                     
my-test-app_frontend_1   /bin/bash /app/run.sh start      Up       35729/tcp, 8000/tcp
my-test-app_nginx_1      nginx -g daemon off;             Exit 1
my-test-app_postgres_1   docker-entrypoint.sh postgres    Up       0.0.0.0:5432->5432/tcp                     
my-test-app_redis_1      docker-entrypoint.sh redis ...   Up       0.0.0.0:6379->6379/tcp                     
my-test-app_worker_1     celery worker -A app.tasks ...   Up                                   

@inactivist Do you want to take a stab at it using something like wait-for-it or Docker healthcheck? My nginx container just gives me a 502 or 504 error until Webpack boots up, which is not ideal but the alternative (no error) might be even more confusing.

I created an issue for this and will close this PR as I don't think it solves the underlying problem: #87

@inactivist
Copy link

inactivist commented Jul 15, 2020

@inactivist Do you want to take a stab at it using something like wait-for-it or Docker healthcheck? My nginx container just gives me a 502 or 504 error until Webpack boots up, which is not ideal but the alternative (no error) might be even more confusing.

I'll take a look at it soon. We'll continue this on #87

@inactivist
Copy link

inactivist commented Jul 16, 2020

I created an issue for this and will close this PR as I don't think it solves the underlying problem: #87

Upon reflection, I think this is a valid PR and needs to be merged, as the startup ordering sequence should guarantee the backend host is available on the Docker network before nginx service is started.

At a minimum, the depends_on clause should include the backend service since absence causes nginx service termination. Not sure the healthcheck is necessary, further investigation needed.

Any Webpack compilation issues should be dealt with separately, IMO

@Buuntu Buuntu merged commit 2d8e36f into Buuntu:master Jul 16, 2020
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

Successfully merging this pull request may close these issues.

3 participants