I'm trying to run Nginx in docker, but the Nginx keeps failing.
Nginx config file:
worker_processes 1;
error_log /var/log/nginx/my_error.log;
pid /var/log/nginx/nginx.pid;
events {
worker_connections 1024; # increase if you have lots of clients
accept_mutex off; # set to 'on' if nginx worker_processes > 1
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
upstream app_server {
server localhost:5000 fail_timeout=0;
}
server {
client_max_body_size 4G;
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
# we don't want nginx trying to do something clever with
# redirects, we set the Host: header above already.
proxy_redirect off;
proxy_pass http://localhost:5000;
}
listen 443 ssl;
ssl_certificate /etc/ssl/certificate.pem;
ssl_certificate_key /etc/ssl/key.pem;
}
}
Dockerfile:
RUN apt-get update && apt-get install -y nginx
COPY ssl/certificate.pem /etc/ssl/certificate.pem
COPY ssl/key.pem /etc/ssl/key.pem
COPY nginx_configuration/nginx.conf /etc/nginx/nginx.conf
EXPOSE 443
EXPOSE 5000
RUN /etc/init.d/nginx start
CMD ["python3", "my_app"]
But when I check the nginx status:
/etc/init.d/nginx status
[FAIL] nginx is not running ... failed!
When I run:
/etc/init.d/nginx start
Everything works as expected.
I checked the log files, there are all empty.
Thanks, Omer
This line is only being executed during image creation. So when a container is created "it does nothing"
RUN /etc/init.d/nginx start
What you are really running inside your container is this python script. I think there is no reference to it in your question.
CMD ["python3", "my_app"]
You can use the following Dockerfile
FROM nginx
COPY ssl/certificate.pem /etc/ssl/certificate.pem
COPY ssl/key.pem /etc/ssl/key.pem
COPY nginx_configuration/nginx.conf /etc/nginx/nginx.conf
EXPOSE 443
EXPOSE 5000