I’m new to web applications landscape and just trying to deploy a basic Django application with Gunicorn, Nginx and podman (version 4.4.1) on Red Hat Linux Enterprise 8.7.
Dockerfile for Nginx is the official image from Docker Hub v 1.25.1.
There’s no docker-compose/podman-compose available on the server.
I’m starting the build by creating a dedicated network:
podman network create testapp-net
The next component is Django application:
podman build -t testapp-django -f src/testapp-django/compose/django/Dockerfile .
Dockerfile for the app is based on Ubuntu base image and I’m exposing port 8000:
FROM ubuntu:22.04
...
RUN addgroup --system django
&& adduser --system --ingroup django django
...
WORKDIR /app
...
RUN chmod +x /app
...
EXPOSE 8000
...
COPY src/testapp-django/compose/django/entrypoint /entrypoint
RUN sed -i -e 's/^M$//' /entrypoint
RUN chmod +x /entrypoint
RUN chown django /entrypoint
COPY src/testapp-django/compose/django/start /start
RUN sed -i -e 's/^M$//' /start
RUN chmod +x /start
RUN chown django /start
RUN chown -R django:django /app
USER django
ENTRYPOINT ["/entrypoint"]
/entrypoint:
set -o errexit
set -o pipefail
set -o nounset
exec "$@"
/start:
set -o errexit
set -o pipefail
set -o nounset
python3 /app/manage.py migrate
gunicorn testapp.wsgi:application --bind 0.0.0.0:8000 --chdir=/app
Starting the Django app is successful:
podman run -d -p 8010:8000 --name testapp-django --env-file src/testapp-django/.env --network testapp-net testapp-django /start
Response:
[2023-07-07 10:23:41 +0000] [24] [INFO] Starting gunicorn 20.1.0
[2023-07-07 10:23:41 +0000] [24] [INFO] Listening at: http://0.0.0.0:8000 (24)
[2023-07-07 10:23:41 +0000] [24] [INFO] Using worker: sync
[2023-07-07 10:23:41 +0000] [26] [INFO] Booting worker with pid: 26
In the next step I want to start Nginx.
Dockerfile:
FROM nginx:1.25.1
RUN rm /etc/nginx/conf.d/default.conf
COPY src/testapp-django/compose/nginx/nginx.conf /etc/nginx/conf.d
My nginx.conf file:
upstream testapp-django {
server testapp-django:8000;
}
server {
listen 80;
location / {
proxy_pass http://testapp-django;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
client_max_body_size 20M;
}
}
podman build -t testapp-nginx -f src/testapp-django/compose/nginx/Dockerfile .
When I run the container though:
podman run -p 1337:80 --name testapp-nginx --network testapp-net testapp-nginx
I’m getting the following response:
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/07/07 14:48:34 [emerg] 1#1: host not found in upstream "testapp-django:8000" in /etc/nginx/conf.d/nginx.conf:2
nginx: [emerg] host not found in upstream "testapp-django:8000" in /etc/nginx/conf.d/nginx.conf:2
I was looking for solution in similar posts on SO, but without any success.
Inspect on app container, I see the following for the network:
"NetworkSettings": {
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"Bridge": "",
"SandboxID": "",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"8000/tcp": [
{
"HostIp": "",
"HostPort": "8000"
}
]
},
"SandboxKey": "/run/user/1632100669/netns/netns-10b5a628-1e92-a4ac-1800-2957e0edaf1c",
"Networks": {
"testapp-net": {
"EndpointID": "",
"Gateway": "10.89.1.1",
"IPAddress": "10.89.1.17",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "16:cb:3d:2a:d1:43",
"NetworkID": "testapp-net",
"DriverOpts": null,
"IPAMConfig": null,
"Links": null,
"Aliases": [
"2a14008a1c9d"
]
}
}
}
The same on nginx container:
"NetworkSettings": {
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"Bridge": "",
"SandboxID": "",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "1337"
}
]
},
"SandboxKey": "",
"Networks": {
"testapp-net": {
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"NetworkID": "testapp-net",
"DriverOpts": null,
"IPAMConfig": null,
"Links": null,
"Aliases": [
"a4a11b846dbc"
]
}
}
}
2
Answers
Managed to make it work by creating a pod first:
Then all containers are created with
--pod testapp
option:This way Nginx sees the Django app.
I faced other issues afterwards that had to do with permissions when running in rootless mode, but managed to solve these issues following this post: https://www.redhat.com/sysadmin/container-permission-denied-errors
Just as a test, can you try to give your upstream an other name?
I mean just editing your
nginx.conf
, so that your docker container and the upstream have different identifiers: