Docker Alpine a tutorial on building a Nginx environment

Source: Internet
Author: User
Tags addgroup geoip inotify json openssl docker ps docker hub docker run


Docker Alpine Construction Nginx

1,pull a base image

As for how to pull own mirroring and build mirrors can refer to Docker hub simple use can also pull the Docker hub in this chapter of the Mirror

[Root@gitlab conf]# Docker Pull Marksugar/alpine
Using default Tag:latest
Latest:pulling from Marksugar/alpine

E110a4a17941:already exists
92c6475c18dd:pull Complete
Digest:sha256:5ae1b32053247f3d251fe5ee56aa817d330cb007603272985a0aab0b79a4c9b3
status:downloaded newer image for Marksugar/alpine:latest


2,dockerfile

From Marksugar/alpine
Maintainer Wwww.111cn.net
RUN addgroup-g 499-s nginx \
&& adduser-hdu 499-s/sbin/nologin-g ' Web server '-G nginx nginx \
&& cd/usr/local \
&& curl-so http://nginx.org/download/nginx-1.10.1.tar.gz \
&& Tar xf nginx-1.10.1.tar.gz \
&& RM-RF nginx-1.10.1.tar.gz \
&& CD nginx-1.10.1 \
&& apk--update--no-cache add GeoIP geoip-dev pcre libxslt gd openssl-dev pcre-dev zlib-dev build-base linux-head ERs libxslt-dev gd-dev openssl-dev libstdc++ libgcc patch logrotate supervisor Inotify-tools && rm-rf/var/cache/ apk/*
Run Run./configure \
--prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--user=nginx \
--group=nginx \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_flv_module \
--with-http_mp4_module \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--HTTP-FASTCGI-TEMP-PATH=/VAR/TMP/NGINX/FASTCGI \
--HTTP-UWSGI-TEMP-PATH=/VAR/TMP/NGINX/UWSGI \
&& make && make install \
&& mkdir-p/var/tmp/nginx/{client,fastcgi,proxy,uwsgi} \
&& echo "daemon off;" >>/etc/nginx/ngnix.conf \
&& apk del wget
ENV Path/usr/local/nginx/sbin: $PATH
Expose 80
CMD ["/usr/local/nginx/sbin/nginx"]


3,build

Docker build-t Marksugar/nginx Dockerfile


4,run up.

[Root@gitlab apline-nginx]# Docker run--name mynginx-d-P 81:80 Marksugar/nginx
e2b7783eacde80337801a1e1c5d0962abd0b2770e820b9523501682716b6b817
[Root@gitlab apline-nginx]# Docker Ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
E2B7783EACDE Marksugar/nginx "/usr/local/nginx/sbi" 2 seconds ago up 1 seconds 0.0.0.0:81-&gt ; 80/tcp Mynginx
B889bfd7a6ee marksugar/nginx:8.33 "/bin/bash" hours ago up 4 hours 0.0.0.0:80-&gt ; 80/tcp Nginx
[Root@gitlab apline-nginx]#

Then you will see a welcome page

Nginx.png

1,dockerfile

Docker mount data volumes, refer to Docker networks and data volumes

Mount Nginx configuration file and root directory


From Marksugar/alpine
Maintainer Wwww.111cn.net
RUN addgroup-g 499-s nginx \
&& adduser-hdu 499-s/sbin/nologin-g ' Web server '-G nginx nginx \
&& cd/usr/local \
&& curl-so http://nginx.org/download/nginx-1.10.1.tar.gz \
&& Tar xf nginx-1.10.1.tar.gz \
&& RM-RF nginx-1.10.1.tar.gz \
&& apk--update--no-cache add GeoIP geoip-dev pcre libxslt gd openssl-dev \
Pcre-dev zlib-dev build-base linux-headers libxslt-dev gd-dev \
libstdc++ LIBGCC Patch logrotate Supervisor Inotify-tools
workdir/usr/local/nginx-1.10.1
RUN./configure \
--prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--user=nginx \
--group=nginx \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_flv_module \
--with-http_mp4_module \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--HTTP-FASTCGI-TEMP-PATH=/VAR/TMP/NGINX/FASTCGI \
--HTTP-UWSGI-TEMP-PATH=/VAR/TMP/NGINX/UWSGI \
&& make && make install \
&& mkdir-p/var/tmp/nginx/{client,fastcgi,proxy,uwsgi} \
&& echo "daemon off;" >>/etc/nginx/nginx.conf \
&& apk del wget \
&& rm-rf/usr/local/nginx-1.10.1 \
&& rm-rf/var/cache/apk/* \
&& Rm-rf/etc/nginx
ENV Path/usr/local/nginx/sbin: $PATH
Expose 80
CMD ["/usr/local/nginx/sbin/nginx"]


2, mount the configuration file

Run up and mount the Nginx configuration file and the directory defined in the configuration file are also mounted
-v/data/nginx/conf:/etc/nginx/
-v/data/nginx/wwwlog:/data/nginx/wwwlog/
-v/data/nginx/wwwroot:/data/nginx/wwwroot/

These three paths map the local conf file to the Nginx configuration file in the container, respectively.

[Root@gitlab data]# tree/data/
/data/
└──nginx

├──conf
│├──conf.d
│├──default.d
│├──fastcgi.conf
│├──fastcgi_params
│├──koi-utf
│├──koi-win
│├──mime.types
│├──nginx.conf
│├──nginx.tar.gz
│├──scgi_params
│├──uwsgi_params
│├──vhost
││└──www.conf
│└──win-utf
├──wwwlog
│├──error_nginx.log
│└──www.com.log
└──wwwroot
└──index.html

7 Directories, files


[Root@gitlab data]#
[Root@gitlab apline-nginx]# Docker run--name mynginx-d-P 81:80-v/data/nginx/conf:/etc/nginx/-v/data/nginx/wwwlog:/d ata/nginx/wwwlog/-v/data/nginx/wwwroot:/data/nginx/wwwroot Marksugar/nginx
240c993352560f76a90d493d3f00253472c3e55858e02b345ad9c66fb40c4001
[Root@gitlab apline-nginx]# Docker Ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
240c99335256 Marksugar/nginx "/usr/local/nginx/sbi" minutes ago up minutes 0.0.0.0:81-&gt ; 80/tcp Mynginx

3,nginx configuration file

The Nginx primary configuration file is basically consistent, as follows:

[Root@gitlab conf]# Cat nginx.conf

User Nginx Nginx;
Error_log/data/nginx/wwwlog/error_nginx.log Crit;
Pid/var/run/nginx.pid;
Worker_rlimit_nofile 51200;

Events {
Use Epoll;
Worker_connections 51200;
}

HTTP {

Include Mime.types;
Default_type Application/octet-stream;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 32k;
Large_client_header_buffers 4 32k;
Client_max_body_size 50m;
Sendfile on;
Tcp_nopush on;
Keepalive_timeout 120;
Server_tokens off;
Tcp_nodelay on;

Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
Fastcgi_buffer_size 64k;
Fastcgi_buffers 4 64k;
Fastcgi_busy_buffers_size 128k;
Fastcgi_temp_file_write_size 128k;

gzip on;
Gzip_buffers 8k;
Gzip_comp_level 6;
Gzip_http_version 1.1;
Gzip_min_length 256;
Gzip_proxied any;
Gzip_vary on;
Gzip_types
Text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
Text/javascript Application/javascript Application/x-javascript
Text/x-json Application/json Application/x-web-app-manifest+json
Text/css Text/plain text/x-component
Font/opentype Application/x-font-ttf Application/vnd.ms-fontobject
Image/x-icon;
Gzip_disable "Msie6";


Open_file_cache max=1000 inactive=20s;
Open_file_cache_valid 30s;
Open_file_cache_min_uses 2;
Open_file_cache_errors on;

Log_format access ' $remote _addr-$remote _user [$time _local] ' $request '
' $status $body _bytes_sent ' $http _referer '
' $http _user_agent ' $http _x_forwarded_for ';

Log_format upstream2 ' $proxy _add_x_forwarded_for $remote _user [$time _local] "$request" $http _host '
' $body _bytes_sent ' $http _referer ' "$http _user_agent" $ssl _protocol $ssl _cipher '
' $request _time [$status] [$upstream _status] [$upstream _response_time] "$upstream _addr";
###########################################################################################
Include vhost/*.conf;
}
Daemon off;
[Root@gitlab conf]#
Include vhost/www.conf

[Root@gitlab vhost]# Cat www.conf
server {

Listen 80;
server_name localhost;
Location/{
Root/data/nginx/wwwroot;
Index index.php index.html index.htm;
}
# location ~ *\. (php|php5.3.27)? $ {
# root Html/blog;
# Fastcgi_pass 127.0.0.1:9000;
# Fastcgi_index index.php;
# include fastcgi.conf;
#        }
Access_log/data/nginx/wwwlog/www.com.log;
}
[Root@gitlab vhost]#
Index.html

[Root@gitlab wwwroot]# cat/data/nginx/wwwroot/index.html
[Root@gitlab wwwroot]#

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.