使用 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
页面内容,刷新页面也会变化。快去试试吧