Inside Nginx docker image

Run docker image

Convinience docker file with vim installed

    # nginx image
    FROM nginx

    RUN apt-get update
    RUN apt-get install -y vim


docker build -t nginx .

Run (By default, nginx listens on post 80)

docker run -it -p 80:80 nginx bash

Inside docker container

a) Nginx version >

nginx -v
nginx version: nginx/1.15.8

b) Default page which runs upon starting nginx server


c) Log files

Access logs : Has the details of all the requests made to the server


Error logs : Has the details of all the errors made while accessing server


d) Start server

service nginx start (or simply hit) nginx

Open localhost on your browser (or hit or local ip address)

You should see the default nginx home page. You can replace the index.html and build your own content

e) Stop server

service nginx stop

f) Reload server

service nginx reload

g) See compile configurations

nginx -V

It will look something like this,

configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/ --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.15.8/debian/debuild-base/nginx-1.15.8=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-specs=/usr/share/dpkg/no-pie-link.specs -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'

h) Check if service is running

Identify the pid-path in the configurations. In our case it is /var/run/

When nginx service is started, this file will be created. When service is stopped, this file will be destroyed. Hence whenever this file doesnt exist, it means no server is running.