docker3 docker-compose.yml 文件编写

docker-compose.yml文件了 到nodeapp 顶级目录操作 文件下操作
vi docker-compose.yml

内容如下:
// 不能使用镜像的名字了 需要打包编译 把images文件下的node文件进行构建
// depends_on依赖的容器
version: "2"
services:
  db:
    image: mariadb
    environment:
      MYSQL_ROOT_PASSWORD: "123456"
      MYSQL_DATABASE: "nodeapp"
      MYSQL_USER: "guozimo"
      MYSQL_PASSWORD: "123456"
    volumes:
      - dbdata:/var/lib/mysql
  node:
    build:
      context: "./images/node"
      dockerfile: Dockerfile
    depends_on:
      - db  
  web:
    image: nginx
    ports:
      - "8080:80"  
    depends_on:
      - node   
    volumes:
      - "./images/nginx/conf.d:/etc/nginx/conf.d"  
      - "./images/node/web/public:/public" 
volumes:
  dbdata:
    driver: local  


   
    vi default.conf
    下面是default.conf的内容
    静态文件的处理 动态文件的处理
    curl http://127.0.0.1:3000

    server{
      listen 80;
      server_name localhost 39.105.91.188;
      location /{
        root /public;
        index index.html;
      }
      location /api{
        proxy_pass http://127.0.0.1:3000
      }
    }  


    docker-compose up  
    注释代码:
    /**
    **/


let http =require("http");
http.createServer(function(req,res){
 res.end("3000");
}).listen(3000,function(){
    console.log('node server start at port 3000')
});

docker-compose down
docker-compose up --build 
// 修改代码后需要重新编译 重新编译node镜像


关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
 防火墙重启
 systemctl restart docker


server{
      listen 80;
      server_name localhost 39.105.91.188;
      location /{
        root /public;
        index index.html;
      }
      location /api{
        proxy_pass http://node:3000;
      }
    } 


    根目录访问:
    curl http://localhost:8080/api

    继续修改server.js
    echo index.html > index.html
 [root@guozimo public]# echo 404.html > 404.html
 
 如果docker-compose up --build
 访问curl http://locahost:8080/api 数据库访问报错
 可以尝试更新一下
 docker pull mysql
 docker pull mariadb
 再重新docker-compose up --build
 重新访问 curl http://locahost:8080/api

      


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值