DataLife Engine / Разворачиваем NGINX в Docker

Разворачиваем NGINX в Docker


Устанавливаем движок Docker'a в CentOS:
yum-config-manager     --add-repo     https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io -y

Запускаем движок Docker'a:
systemctl start docker

Проверяем статус:
systemctl status docker

Содержимое Dockerfile:
vi Dockerfile-Ubuntu-Nginx
############################################################
# Dockerfile to build Nginx Installed Containers
# Based on Ubuntu with LTS
############################################################

# Set the base image to Ubuntu 
FROM ubuntu:20.04

# File Author / Maintainer
MAINTAINER Sobir Akbarov <[email protected]>

# Update the repository
RUN apt-get update

# Install necessary tools
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get install apt-utils dialog iproute2 dnsutils inetutils-ping ncat nano less wget -y

# Download and install NGINX
RUN apt-get install nginx -y  

# Remove the default NGINX configuration file
RUN rm -v /etc/nginx/nginx.conf

# Copy a configuration file from the current directory
ADD nginx.conf /etc/nginx/

# Append "daemon off;" to the ending of the configuration
RUN echo "daemon off;" >> /etc/nginx/nginx.conf

# Expose ports
EXPOSE 80
EXPOSE 443

# Set the default command to execute
# when creating a new container
CMD service nginx start

Содержимое nginx.conf:
vi nginx.conf
user  www-data;
pid   /run/nginx.pid;
worker_processes  auto;
worker_rlimit_nofile 65535;
error_log  /var/log/nginx/error.log warn;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 65535;
    use epoll;
    multi_accept on;
}


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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    server_names_hash_bucket_size 64;
    server_tokens off;
    gzip  on;

    server {
        listen       0.0.0.0:80 default_server;
        server_name  localhost;
        root	     /var/www/html;

        location / {
            deny all;
        }

        error_page 404 /404.html;
    	    location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
    	    location = /50x.html {
        }
    }    

    include /etc/nginx/conf.d/*.conf;
}

Выполняем сборку образа командой:
docker build -f Dockerfile-Ubuntu-Nginx -t nginx:custom .

Просмотр доступных образов:
docker images

Запускаем образ nginx:
docker run --rm -d --name web -v /data/app:/var/www/html -p 0.0.0.0:80:80 nginx:custom

Проверяем запущенный процесс контейнера:
docker ps
22-06-2021, 16:56
Вернуться назад