Docker环境下部署项目流程

部署项目通常会浪费很多时间,使用docker容器化可以大大压缩这些时间,以下介绍在docker容器内部署项目。

目录结构

> tree .

.

├── Dockerfile

├── html

│   ├── css

│   │   └── index.css

│   ├── Dockerfile

│   ├── images

│   │   ├── background.png

│   │   ├── bottom-left-center.png

│   │   ├── bottom-right-center.png

│   │   ├── \ branch.png

│   │   ├── img_background.png

│   │   ├── normal-hover.png

│   │   ├── normal.png

│   │   └── top-centre.png

│   ├── index.html

│   ├── js

│   │   └── rem_js.js

│   └── README.md

└── nginx.conf

4 directories, 15 files

编写Dockerfile文件

FROM ubuntu:latest # 使用较小的ubuntu作为虚拟环境

RUN apt-get update && apt-get install -y vim && apt-get install -y nginx # 安装nginx

RUN rm -rf /usr/share/nginx/html/* && rm -rf /etc/nginx/nginx.conf # 删除nginx原有文件

COPY nginx.conf /etc/nginx/ # 复制nginx文件配置

COPY html /usr/share/nginx/html/ # 将项目文件写入nginx的目录

EXPOSE 80 # 暴露80端口

CMD ["nginx","-g","daemon off;"] # 启动nginx

配置nginx文件

worker_processes  auto;

error_log  /var/log/nginx/error.log notice;

pid        /var/run/nginx.pid;

events {

    worker_connections  1024;

}

http {

    include       /etc/nginx/mime.types;

    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;

    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

    server { # nginx默认文件是没有server的

        listen       80;

        server_name  192.168.0.123;

        client_max_body_size 5M;

        location / {

                root   html;

                index  index.html index.htm;

        }

    }

}

执行构建命令

docker build -t myproject:1.0.0 .

执行启动容器

docker run -it --name myproject -p 10800:80 -d myproject:1.0.0

验证结果

浏览器输入http://192.168.0.123:10800/显示页面即完成部署。

  • 31
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

countrysides

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

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

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

打赏作者

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

抵扣说明:

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

余额充值