DEV Community

Sean
Sean

Posted on • Updated on

Project #1: Deploy a Docker Container on Linode (status: Abandoned)

Status: Abandoned

Background

A couple of years ago, I worked on a project that dockerized a Django application that displayed a basic 'Upload' form and uploaded the files within the same container

https://github.com/drivelous/docker-ubuntu18.04-django3.0.2

It has a local and production build with the production build firing up an nginx service.

That repo is the product of customizing code that I wrote when I followed this tutorial: https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/

Progress Log
2022-12-10
I did everything but couldn't do this. I did a final ~2 hour session trying to get it to work but decided to start a new tutorial from https://testdriven.io/

Since it's a paid course, I know that the code will work. At some point in time, I will return back to this after my knowledge of Docker and Docker Compose gets better.

2022-11-28
I've put in a few hours this past week and while I've learned a bit, ultimately, I ended up posting on StackOverflow to see if anyone could help me out -- https://stackoverflow.com/questions/74606942/docker-nginx-service-cant-communicate-with-django-service-and-returning-bad-req

I also just want to note that this nginx/django guide is great: https://mattsegal.dev/nginx-django-reverse-proxy-config.html

2022-11-22
Still having issues but inching a bit closer.

I realize now that using an official nginx Docker image reroutes all the logs that would normally be in /var/log/nginx/ to either stdout/stderr. This is useful so that outside of the container I can run docker logs <container_name> but since I was looking for debug level logs it didn't help much -- I know my server is returning 400, but why?

So in nginx.conf I added the line below and rebuild the image

upstream polls_django {
    server web:8000;
}

error_log /var/log/nginx/error_foo.log debug;  <--
...
Enter fullscreen mode Exit fullscreen mode

When running docker exec -it <container_name> /bin/sh I took a peak at error_foo.log and saw a lot of Operation timed out requests

2022/11/23 01:34:39 [info] 7#7: *11 client timed out (110: Operation timed out) while waiting for request, client: xx.xx.xxx.xx, server: 0.0.0.0:80
2022/11/23 01:38:40 [info] 7#7: *15 client timed out (110: Operation timed out) while waiting for request, client: xx.xx.xxx.xx, server: 0.0.0.0:80
Enter fullscreen mode Exit fullscreen mode

I had a hunch it was because my environment variables .env.prod didn't have my IP in DJANGO_ALLOWED_HOSTS (which I thought would explain why it works locally but not in production) but that wasn't it.

I have a hunch that something is amiss. Looking at the web application logs, there are no requests that made it to Django. nginx is not able to reach it for some reason.

I've worked an hour on this. I gotta come back to it later on.

2022-11-21
Locally, running the production command, I can get it to work

docker-compose -f docker-compose.prod.yml up --build
Enter fullscreen mode Exit fullscreen mode

Local:
Image description

But when I run it on my Linode, I'm getting Bad Request 400.

All I can see in my logs is the 400

$ docker logs docker-ubuntu1804-django302_nginx_1
$ [22/Nov/2022:02:58:25 +0000] "GET / HTTP/1.1" 400 154 "-"...
Enter fullscreen mode Exit fullscreen mode

I've tried getting a shell into nginx and then running cat on the nginx error.log but it freezes

$ docker exec -it docker-ubuntu1804-django302_nginx_1 /bin/sh
$ [nginx] cd /var/log/nginx
$ [nginx] cat error.log
--> (stuck hanging here)
Enter fullscreen mode Exit fullscreen mode
  1. I'm still trying to figure out what's wrong
  2. I can't seem to find the error logs within my container

Top comments (1)

Collapse
 
venkatamutyala profile image
venkatamutyala

Have you tried doing a curl? Ex. use a curl when running it locally and then use that same curl command against the linode instance? Also, try the local curl, locally within the linode instance.