docker-compose快速部署nginx

一、概述

bitnami镜像

https://registry.hub.docker.com/r/bitnami/nginx

准备

目前docker-compose创建nginx脚本不支持直接挂载文件,只能挂载文件夹,通常我们需要挂载nginx.conf文件,所以必须先在宿主机上生成同名文件。

# 先用docker创建nginx,复制对应文件
mkdir -p nginx/conf nginx/conf.d && cd nginx
docker run --name nginx-demo -d nginx
# 复制文件
docker cp nginx-demo:/etc/nginx/nginx.conf ./conf/nginx.conf
docker cp nginx-demo:/etc/nginx/conf.d/default.conf ./conf.d/default.conf
docker cp nginx-demo:/usr/share/nginx/html .
# 删除容器
docker stop nginx-demo && docker rm nginx-demo

否则报错:

[root@VM_80_127_linux nginx]# docker-compose up -d 
Starting nginx ... error

ERROR: for nginx  Cannot start service nginx: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/opt/software/docker/nginx/conf/nginx.conf" to rootfs at "/etc/nginx/nginx.conf": mount/opt/software/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf (via/proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

二、docker-compose

vim docker-compose.yml

version: '3.1'

services:
  nginx:
    image: nginx
    container_name: nginx
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 11086:11086
    volumes:
      - ./conf.d:/etc/nginx/conf.d
      - ./conf/nginx.conf:/etc/nginx/nginx.conf
      - ./logs:/var/log/nginx
      - ./html:/etc/nginx/html

三、基础命令

# 启动
docker-compose up -d
# 列表
docker-compose ps
# 日志
docker-compose logs nginx
# 停止
docker-compose down
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码上富贵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值