CentOS7 Docker Nginx deployment and operation detailed explanation

I found some data deployment on the Internet, and there are different problems. Now I will summarize my deployment process.

1、 Resource preparation

Dockerfile

# " ported" by Adam Miller <[email protected]>from 
# https://github.com/fedora-cloud/Fedora-Dockerfiles 
# 
# Originally written for Fedora-Dockerfiles by 
# scollier <[email protected]> 
 
FROM centos:centos7 
MAINTAINER The CentOS Project <[email protected]> 
 
RUN yum -y update; yum clean all 
RUN yum -y install epel-release tar ; yum clean all 
RUN yum -y install nginx ; yum clean all 
ADD nginx.conf /opt/deploy/nginx/nginx.conf 
RUN echo "daemon off;">>/opt/deploy/nginx/nginx.conf 
# RUN curl https://git.centos.org/sources/httpd/c7/acf5cccf4afaecf3afeb18c50ae59fd5c6504910 \ 
# | tar -xz -C /usr/local/nginx/html \ 
# - - strip-components=1 
# RUN sed -i -e 's/Apache/nginx/g'-e '/apache_pb.gif/d' \  
# /usr/local/nginx/html/index.html 
 
EXPOSE 80 
 
# CMD ["/usr/local/nginx/sbin"]

Note: The path needs to exist and correspond to the system

nginx.conf file

# For more information on configuration, see: 
# * Official English Documentation: http://nginx.org/en/docs/ 
# * Official Russian Documentation: http://nginx.org/ru/docs/ 
user nginx; 
worker_processes 1; 
error_log /usr/logs/nginx/error.log; 
# error_log /var/log/nginx/error.log notice; 
# error_log /var/log/nginx/error.log info; 
pid    /run/nginx.pid; 
events { 
worker_connections 1024;} 
http { 
include    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 /usr/logs/nginx/access.log main; 
sendfile    on; 
# tcp_nopush   on; 
# keepalive_timeout 0; 
keepalive_timeout 65; 
# gzip on; 
# Load modular configuration files from the /etc/nginx/conf.d directory. 
# See http://nginx.org/en/docs/ngx_core_module.html#include 
# for more information. 
# include /etc/nginx/conf.d/*.conf; 
index  index.html index.htm; 
server { 
listen    80; 
server_name localhost; 
root     /usr/share/nginx/html; 
# charset koi8-r; 
# access_log /var/log/nginx/host.access.log main; 
location / { 
autoindex on; 
} 
# redirect server error pages to the static page /40x.html 
# 
error_page 404       /404.html; 
location = /40x.html { 
} 
# redirect server error pages to the static page /50x.html 
# 
error_page  500 502 503 504 /50x.html; 
location = /50x.html { 
} 
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 
# 
# location ~ \.php$ { 
# proxy_pass  http://127.0.0.1; 
#} 
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
# 
# location ~ \.php$ { 
# root      html; 
# fastcgi_pass  127.0.0.1:9000; 
# fastcgi_index index.php; 
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 
# include    fastcgi_params; 
#} 
# deny access to .htaccess files, if Apache's document root 
# concurs with nginx's one 
# 
# location ~ /\.ht { 
# deny all; 
#} 
} 
# another virtual host using mix of IP-, name-, and port-based configuration 
# 
# server { 
# listen    8000; 
# listen    somename:8080; 
# server_name somename alias another.alias; 
# root     html; 
# location / { 
#  } 
#} 
# HTTPS server 
# 
# server { 
# listen    443; 
# server_name localhost; 
# root     html; 
# ssl         on; 
# ssl_certificate   cert.pem; 
# ssl_certificate_key cert.key; 
# ssl_session_timeout 5m; 
# ssl_protocols SSLv2 SSLv3 TLSv1; 
# ssl_ciphers HIGH:!aNULL:!MD5; 
# ssl_prefer_server_ciphers  on; 
# location / { 
#  } 
#} 
} 

Note: The path needs to exist and correspond to the system

2、 Execute the build image command

Copy the code code as follows:

[ root@localhost nginx]# sudo docker build –rm –tag os7/nginx:centos7 .

Screenshot of execution result:

3、 Check whether the image is successfully installed and built Docker images

4、 Create a container docker run -i -t -d -p 192.168.32.129:81:80 os7/nginx /bin/bash

Note: If 192.168.32.129 is the IP, you need to add it in /etc/hosts

192.168.32.129 localhost

5、 Check if the container is created successfully and start docker ps

6、 Test whether to access curl http://192.168.32.129:81 successfully

There will be this connection refused, what should I do? If there is a solution, we first enter the container

7、 Enter the container docker exec -i -t small_hodgkin /bin/sh

8、 Then execute it in the container (enter directly)

nginx

9、 Execute curl outside the container http://192.168.32.129:81

It succeeded.

10、 Then go outside the virtual machine to access through the browser

So far it succeeded.

Reference materials: https://github.com/CentOS/CentOS-Dockerfiles

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

CentOS7 Docker Nginx deployment and operation detailed explanation
Centos 7 RAID 5 detailed explanation and configuration
Deploy Docker and configure Nginx in CentOS
Centos7 installation and deployment of Airflow detailed
Centos7 installation of PHP and Nginx tutorial detailed
MySQL 8.0 installation and deployment under CentOS, super detailed!
CentOs7.3 compile and install Nginx 1.9.9
Detailed explanation of Spark installation and configuration tutorial under centOS7
Centos8 minimal deployment and installation of OpenStack Ussuri detailed tutorial
Use Nginx and u under CentOS
Centos6.5 installation and deployment of KVM
CentOS 6.x compile and install Nginx
CentOS7.2 and Nginx configuration virtual host
CentOS7.3 install iptables and detailed use
Install and use docker under CentOS 6.8
CentOs7 installation and deployment Zabbix3.4 original
Erlang 20.2 installation and deployment under CentOS 7
Ubuntu installation and deployment Redash operation notes (2020.08)
MySQL 8.0 installation, deployment and configuration under CentOS 6/7
Centos-6.5 installation and deployment of LNMP environment
Centos7 installation and deployment of gitlab server
Installation and deployment of Nginx in Ubuntu
Zabbix installation and deployment and localization under CentOS
n1. Docker installation and operation exceptions encountered
Jenkins installation and deployment tutorial under CentOS 7
Python and scrapy deployment in centos environment
CentOS7 fully automatic installation CD production detailed explanation
Install nginx in centos8 custom directory (detailed tutorial)
How to install and use Docker on CentOS 7
CentOS 6.5 system installation and configuration graphic tutorial (detailed graphic)
CentOS7 and Docker configuration Chinese character set problem
Detailed explanation of building Hadoop environment on CentOS 6.5
Detailed tutorial of installing nginx on centos8 (graphic)
MySQL 8.0 installation, deployment and configuration tutorial on CentOS 8
Centos7.3 install nginx
CentOS 7 install Docker
CentOS7 install Docker
Docker installation (CentOS7 installation)
Centos7 install docker18
centos7 install docker
CentOS7 docker installation
CentOS 6 install Docker
Centos8 install Docker
CentOS deployment Harbor
Installation and cracking of confluence6.3 operation records under Centos
Detailed explanation of Centos 7 system virtual machine bridging mode
Installation and cracking of Jira7 operation records under Centos
Equal Insurance Evaluation: Detailed Explanation of Centos Timeout Exit
Detailed explanation of CentOS7 network setting tutorial in vmware