# 安装Dockerhttps://docs.docker.com/get-docker/# 安装Docker Composehttps://docs.docker.com/compose/install/# CentOS安装Dockerhttps://mp.weixin.qq.com/s/nHNPbCmdQs3E5x1QBP-ueAmkdir -p nginx/{conf,log,html}cd nginx
创建conf/default.conf文件:
server { listen 80; listen [::]:80; server_name localhost; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/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; #}}hello world
创建docker-compose.yaml文件:
services: nginx: image: nginx:latest container_name: nginx restart: unless-stopped privileged: true ports: - 8080:80 - 8443:443 - 8081:81 #预留端口 - 8082:82 #预留端口 volumes: - ./conf:/etc/nginx/conf.d - ./log:/var/log/nginx - ./html:/usr/share/nginx/html
docker-compose up -d
docker ps
docker logs nginx
docker restart nginx
停止并销毁容器:
docker-compose down
docker rmi nginx:latest
rm -rf ./conf ./log ./html
docker pull nginx:latest
docker run -it -d \ --name nginx \ -p 8080:80 \ -p 8443:443 \ -p 8081:81 \ -p 8082:82 \ -v ./conf:/etc/nginx/conf.d \ -v ./log:/var/log/nginx \ -v ./html:/usr/share/nginx/html \ --privileged \ nginx:latest
docker ps
docker logs nginx
docker restart nginx
停止容器:
docker stop nginx
docker rm nginx
docker rmi nginx:latest
rm -rf ./conf ./log ./html
docker pull nginx:latest
wget https://nginx.org/download/nginx-1.28.0.tar.gz
FROM alpine:latestADD nginx-1.28.0.tar.gz /root/RUN cp /etc/apk/repositories /etc/apk/repositories-bak; \ sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories; \ apk update; \ apk add build-base gcc g++ pcre-dev openssl-dev zlib-dev curl ca-certificates; \ adduser -S -s /bin/false -H nginx; \ addgroup -S nginx; \ cd /root/nginx-1.28.0; \ ./configure \ --prefix=/usr/local/nginx \ --user=nginx \ --group=nginx \ --with-compat \ --with-threads \ --with-http_addition_module \ --with-http_auth_request_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_mp4_module \ --with-http_random_index_module \ --with-http_realip_module \ --with-http_secure_link_module \ --with-http_slice_module \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_sub_module \ --with-http_v2_module \ --with-http_v3_module \ --with-mail \ --with-mail_ssl_module \ --with-stream \ --with-stream_realip_module \ --with-stream_ssl_module \ --with-stream_ssl_preread_module; \ make && make install; \ rm -rf /root/nginx-1.28.0WORKDIR /usr/local/nginxCMD ["/usr/local/nginx/sbin/nginx","-g","daemon off;"]
docker build -t nginx:v1 .
docker run -it -d \ --name nginx \ -p 8080:80 \ -p 8443:443 \ -p 8081:81 \ -p 8082:82 \ -v ./log:/usr/local/nginx/logs \ -v ./html:/usr/local/nginx/html \ --privileged \ nginx:v1
docker ps
docker logs nginx
# 从容器中复制nginx.conf文件:docker cp nginx:/usr/local/nginx/conf/nginx.conf nginx.conf# 查看文件:cat nginx.conf# 将nginx.conf文件复制到容器中:# docker cp nginx.conf nginx:/usr/local/nginx/conf/nginx.confdocker restart nginx
停止容器:
docker stop nginx
docker rm nginx
docker rmi nginx:v1
rm -rf ./conf ./log ./html
假设当前ip为192.168.186.128浏览器访问:http://192.168.186.128:8080
https://nginx.org/https://github.com/nginx/nginx
本文链接:https://www.kinber.cn/post/6145.html 转载需授权!
推荐本站淘宝优惠价购买喜欢的宝贝:

支付宝微信扫一扫,打赏作者吧~
