docker中使用alpine linux镜像基础安装nginx服务笔记

容器随docker服务的启动而启动:

docker开机启动

systemctl enable docker

容器启动

1、还没有创建容器的

sudo docker run -it --name=myAlpine --restart=always alpine /bin/sh

2、已经创建了容器的

sudo docker update --restart=always myAlpine

标志:描述
no:不自动重启容器(默认值)
on-failure:如果容器由于错误而退出,则将其重新启动,非零退出代码表示错误
unless-stopped:重新启动容器,除非明确停止容器或者 Docker 被停止或重新启动
always:只要容器停止了,就重新启动


dockerfile生成NGINX

FROM alpine
MAINTAINER allen [email protected]
ADD nginx-1.18.0.tar.gz /tmp
ADD nginx.conf /tmp/nginx.conf
ADD init.sh /tmp/init.sh
WORKDIR /tmp/nginx-1.18.0
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories\
	&& apk add mlocate g++ pcre-dev zlib-dev make\
	&& apk update\
	&& apk upgrade\
	&& addgroup -S nginx\
	&& adduser -S -G nginx -s /sbin/nologin -h /usr/local/nginx nginx\
	&& ./configure --user=nginx --group=nginx\
	&& make\
	&& make install\
	&& mkdir -p /run/nginx /data/www /data/filesCenter /data/logs/www\
	&& mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.back\
	&& mv /tmp/nginx.conf /usr/local/nginx/conf/nginx.conf\
	&& mv /tmp/init.sh /usr/local/nginx/init.sh\
	&& rm -rf /tmp/*\
	&& /usr/local/nginx/sbin/nginx -t
CMD ["/bin/sh","/usr/local/nginx/init.sh"]
# sudo docker build -t alpine-nginx
# sudo docker run -id -p 8000:80 -p 8001:81 -h nginx -v /data/www:/data/www -v /data/filesCenter:/data/filesCenter --restart=always --name=nginx alpine-nginx

nginx.conf

user nginx;
worker_processes  4;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile      on;
    gzip on;
    keepalive_timeout  65;
    log_format main '$remote_addr || $remote_user || $time_local || $request || $status || $body_bytes_sent || $http_referer || $http_user_agent || $http_x_forwarded_for';
    include /data/www/*/*.conf;
} 

init.sh

#!/bin/sh
/usr/local/nginx/sbin/nginx
/bin/sh

cat /data/www/x-software/http.conf

server {
    charset               utf-8;
    client_max_body_size  128M;
    #:后端服务器连接的超时时间_发起握手等候响应超时时间
    #proxy_connect_timeout 600s;
    #:连接成功后_等候后端服务器响应时间_其实已经进入后端的排队之中等候处理(也可以说是后端服务器处理请求的时间)
    #proxy_read_timeout 600s;
    #:后端服务器数据回传时间_就是在规定时间之内后端服务器必须传完所有的数据
    #proxy_send_timeout 600s;
    #client_body_buffer_size 128k;
    #client_header_timeout 600s;
    #client_body_timeout 600s;
    #send_timeout 600s;
    #proxy_buffer_size 4k;
    #proxy_buffers 32 4k;
    #proxy_busy_buffers_size 64k;
    #keepalive_timeout  600s;
    #fastcgi_buffers 8 128k;
    #fastcgi_connect_timeout 600s;
    fastcgi_send_timeout 600s;
    fastcgi_read_timeout 600s;
    #fastcgi_buffer_size 128k;
    #fastcgi_busy_buffers_size 256k;
    #fastcgi_temp_file_write_size 256k;
    
    #gzip on;
    listen                80;
    #listen               [::]:80;
    #default_server ipv6only = on;
    server_name           zctech.tech;
    root                  /data/www/x-software/web;
    index                 index.php;
    access_log            /data/www/x-software/runtime/zctech.tech.access.log;
    error_log   	  /data/www/x-sfotware/runtime/zctech.tech.error.log;

    #正式环境
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    #测试环境
    location /index-test.php {
        try_files $uri $uri/ /index-test.php$is_args$args;
    }
    #开始环境
    location /index-dev.php {
        try_files $uri $uri/ /index-dev.php$is_args$args;
    }

    #location /upload/ruomei/ {
    #   autoindex on;
    #}

    # uncomment to avoid processing of calls to non-existing static files by Yii
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
        #try_files $uri =404;
    #}
    #error_page 404 /404.html;

    # deny accessing php files for the /assets directory

    location ~ ^/assets/.*\.php$ {
        deny all;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 192.168.2.108:9000;
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        try_files $uri =404;
    }

    location ~* /\. {
        deny all;
    }
}

你可能感兴趣的:(LNMP,nginx,alpine,linux)