0

We have the following DockerFile

FROM nginx
RUN apt-get update && apt-get install -y curl \
&& rm -rf /var/lib/apt/lists/*
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 443
WORKDIR /etc/nginx
# Set the default command to execute
# when creating a new container
CMD ["nginx", "-g", "daemon off;"]

Here is the nginx.conf below. The container builds and runs fine.Curling the /health endpoint works both inside the container and outside. The moment we add a healthcheck to the docker compose file like this, not only does the healthcheck not pass but the /health endpoint can't be curled either inside or outside the container also the container doesn't accept any requests. The healthcheck statement breaks it totally. This is happening on digital ocean droplet running docker 18.06 ubuntu 16.04

 healthcheck: 
   test: curl -f https://myserver.co.uk/health || exit 1
   interval: 60s
   timeout: 30s
   retries:2
   start_period:5m

Nginx.conf

 user www-data;
 worker_processes 4;
 pid /run/nginx.pid;

 events {
    worker_connections 768;
  # multi_accept on;
 }

 http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##

#include /etc/nginx/naxsi_core.rules;

##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##

#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;

##
# Virtual Host Configs
##


    #ssl_dhparam /etc/ssl/private/dhparam.pem;

server {  
        listen 443;
            ssl         on;
        ssl_certificate       /etc/nginx/certs/push_bundle.crt;
        ssl_certificate_key   /etc/nginx/certs/push_bundle.crt;

        location /health {
            return 200 'alive';
            add_header Content-Type text/plain;
        }

        location / {
            proxy_http_version 1.1;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass http://localhost:1337/;
        }

}

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.