docker-compse 安装nginx 配置目录挂载
一.新建一个启动服务的目录
mkdir /usr/local/docker/compose
cd /usr/local/docker/compose
二.新建文件docker-compose.yml
注意:文件名字必需是docker-compose.yml
version: '3.8'
services:
nginx:
container_name: mynginx
image: nginx
restart: always
ports:
- 8080:80
- 443:443
privileged: true
volumes:
- ./nginx:/etc/nginx
- ./nginx/logs:/var/log/nginx
- /wwwroot:/wwwroot
environment:
- TZ=Asia/Shanghai
networks:
- myweb
networks:
myweb:
driver: bridge
三.新建角本文件 init-compose.sh
#!/bin/bash
docker run -d --name nginxtest nginx #启动一个nginx容器
docker cp nginxtest:/etc/nginx ./ #复制容器里的nginx目录到当前目录
docker rm -f nginxtest #停止并删除nginx容器
#修改default.conf配置文件
tee $PWD/nginx/conf.d/default.conf<<-'EOF'
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
error_log /var/log/nginx/localhost.error.log;
# 配置前端静态文件目录
location / {
root /wwwroot/html;
index index.html index.htm index.php;
}
#location ~ \.php$ {
# fastcgi_pass myphp73-fpm:9000; #myphp73-fpm容器的名字
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
#}
# 配置后台go服务api接口服务 代理到8877端口
#location ~ ^/goadminapi/ {
# proxy_set_header Host $http_host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# rewrite ^/goadminapi/(.*)$ /$1 break;
# proxy_pass http://127.0.0.1:8877;
# }
}
EOF
#新建html目录
mkdir -p /wwwroot/html
#新建index.html文件
tee /wwwroot/html/index.html<<-'EOF'
hello /wwwroot/html/index.html haimait
EOF
#启动服务
docker-compose up -d
四.启动服务
chmod +x init-compose.sh
./init-compose.sh
此时服务已经启动成功了.使用角本是不是很爽,嘿嘿...
其它操作
docker ps -a #查看启动的服务
docker-compose -h #帮助命令
docker-compose down #停止并删除服务
docker-compose restart #重启服务
docker-compose stop #停止服务
docker-compose start #停止服务
docker-compose logs #停止日志
[Haima的博客]
http://www.cnblogs.com/haima/