当前位置: 首页 > news >正文

alpine linux nginx,Docker alpine构建nginx

I. Docker alpine构建nginx

II. 1,pull一个基础镜像

至于如何pull自己的镜像和构建镜像可以参考Docker Hub简单使用也可以pull本章中的docker hub的镜像

[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

III. 2,Dockerfile

FROM marksugar/alpine

MAINTAINER wwww.linuxea.com

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-headers 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"]

IV. 3,build

docker build -t marksugar/nginx Dockerfile

V. 4,run起来

[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->80/tcp mynginx

b889bfd7a6ee marksugar/nginx:8.33 "/bin/bash" 19 hours ago Up 4 hours 0.0.0.0:80->80/tcp nginx

[root@gitlab apline-nginx]#

这时你会看到一个欢迎页面

5c1967c5325842cec010c6abd3e07965.gif

VI. 1,Dockerfile

Docker挂载数据卷,可参考Docker网络和数据卷

挂载nginx配置文件和根目录

FROM marksugar/alpine

MAINTAINER wwww.linuxea.com

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 openssl-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"]

VII. 2,挂载配置文件

run起来并且挂载nginx配置文件以及配置文件中定义的目录也被挂载

-v /data/nginx/conf:/etc/nginx/

-v /data/nginx/wwwlog:/data/nginx/wwwlog/

-v /data/nginx/wwwroot:/data/nginx/wwwroot/

这三个路径分别是将本地的conf文件映射到容器中nginx配置文件

[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, 14 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:/data/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" 23 minutes ago Up 23 minutes 0.0.0.0:81->80/tcp mynginx

VIII. 3,nginx配置文件

nginx主配置文件基本一致,如下:

[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 16 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

Centos7 To Apline

[root@gitlab wwwroot]#

5c1967c5325842cec010c6abd3e07965.gif

除非另有说明,否则本站上的内容根据以下许可进行许可: CC署名-非商业性使用-相同方式共享4.0国际许可协议4.0进行许可

本文作者:www.linuxea.com for Mark

文章链接:http://www.linuxea.com/1423.html (转载请注明本文出处和本章链接)


http://www.taodudu.cc/news/show-7665363.html

相关文章:

  • alpine安装启动mysql_Alpine Linux常用命令
  • alpine 编译c语言,Alpine Linux配置使用技巧
  • alpine 笔记
  • Alpine基本操作
  • Alpine VMware
  • C++编程之 std::forward
  • C++11 move和forward实现原理
  • Linux ip_forward
  • linux ip forward不起作用,linux-ipforward实现
  • association标签传多参
  • MyBatis之association和collection标签
  • MyBatis_延迟加载association和lazyLoadingEnabled详解
  • Mybatis 关联查寻 association 和 collection
  • resultMap中association的各个属性
  • mybaties association使用
  • mybatis的association
  • hexchat(IRC聊天客户端)
  • irc客户端 linux,IRC使用入门
  • java irc_irc使用教程
  • Flink:StandAlone模式部署
  • flink高可用集群搭建(Standalone模式)
  • android中standalone模式,开发 Standalone Android Java 应用程序
  • spark三种模式【Standalone 模式、yarn 运行模式、local(本机)】
  • Standalone是什么?详解Standalone集群的三类进程
  • 图像处理学习笔记——BMP图片详解
  • matlab图像处理bmp,matlab图像坐标原点及方向、BMP图像的原点。
  • GEC6818的bmp图片显示
  • BMP 图像文件
  • BMP图片信息数据解析示例
  • matlab+pca与svd,浅谈 PCA与SVD