docker 简单部署

使用 node 镜像部署

先创建一个简单的html

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title></title>
</head>

<body>
  hello, world
</body>

</html>

编写Dockerfile

FROM node:14-aline
WORKDIR /app
ADD . /app
RUN yarn
EXPOSE 3000
CMD npm start

构建镜像

dokcer build -t simple-app .

运行容器

docker run --rm -p 3000:3000 simple-app

使用docker-compose 构建:

vesion:3
services:
    app:
        build: .
        ports:
            - 3000:3000

使用docker-compose启动

docker-compose up

访问http://localhost:3000就可以看到页面了

使用nginx 镜像部署

编写Dockerfile

nginx.Dockerfile

FROM nginx:alpine
ADD index.html /usr/share/nginx/html/

配置nginx

nginx.conf

server {
    listen       80;
    server_name  localhost;

    root   /usr/share/nginx/html;
    index  index.html index.htm;

    location / {
        expires -1;
    }
}

编写docker-compose.yaml

version:"3"
services:
    nginx-app:
        build:
            context:.
            dockerfile:nginx.Dockerfile
        ports:
            - 4000:80
        volumes:
            - nginx.conf:/etc/nginx/conf.d/default.conf
            - .:/usr/share/nginx/html

使用 docker-compose启动

docker-compose up nginx-app

访问http://localhost:4000就可以看到页面了

更改index.html页面内容,刷新页面也会变化。快去试试吧

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容