tengine 加 node Dockerfile
时间: 2024-06-08 22:09:06 浏览: 26
以下是一个使用 tengine 和 Node.js 的 Dockerfile:
```
FROM node:12-alpine AS build
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
COPY . .
RUN yarn build
FROM openresty/openresty:alpine
RUN apk add --no-cache bash
COPY --from=build /app/build /usr/share/nginx/html
COPY nginx.conf /usr/local/openresty/nginx/conf/nginx.conf
```
该 Dockerfile 将 Node.js 作为构建阶段的基础镜像,在此阶段中,将安装所有 Node.js 依赖项并构建应用程序。在第二个阶段中,将使用 tengine 作为基础镜像,并将应用程序复制到 Nginx 的默认 HTML 目录下。最后,将应用程序的 Nginx 配置文件复制到适当位置。
请注意,此 Dockerfile 假定您的应用程序使用 Nginx 作为 Web 服务器,并使用了一个名为 `nginx.conf` 的配置文件。您需要根据自己的项目需要调整配置文件和文件路径。
相关问题
tengine 和 node 合并一个镜像的 Dockerfile
以下是将 Tengine 和 Node 合并到同一个 Docker 镜像的 Dockerfile:
```Dockerfile
FROM ubuntu:latest
# 安装 Tengine
RUN apt-get update && \
apt-get install -y wget build-essential libpcre3 libpcre3-dev zlib1g-dev libssl-dev && \
wget http://tengine.taobao.org/download/tengine-2.3.2.tar.gz && \
tar zxvf tengine-2.3.2.tar.gz && \
cd tengine-2.3.2 && \
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module && \
make && make install && \
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
# 安装 Node.js
RUN apt-get install -y curl && \
curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
apt-get install -y nodejs
# 添加应用代码
COPY app /app
# 配置 Tengine 和 Node.js
COPY nginx.conf /usr/local/nginx/conf/nginx.conf
WORKDIR /app
RUN npm install && \
npm run build
# 开放端口
EXPOSE 80
# 启动服务
CMD ["nginx", "-g", "daemon off;"]
```
其中,`app` 目录是应用代码所在的目录,`nginx.conf` 是 Tengine 的配置文件,示例配置文件如下:
```nginx
worker_processes auto;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
root /app/dist;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
}
```
这个配置文件将 Tengine 监听 80 端口,并将请求转发到 Node.js 应用的静态文件目录 `/app/dist`。在启动容器时,Tengine 将会自动启动,并将请求代理到 Node.js 应用。
node tengine 做一个镜像的 Dockerfile
以下是使用 node tengine 构建 Docker 镜像的示例 Dockerfile:
```
FROM nginx:latest
RUN apt-get update && apt-get install -y wget && \
wget http://tengine.taobao.org/download/tengine-2.3.2.tar.gz && \
tar -xzvf tengine-2.3.2.tar.gz && \
cd tengine-2.3.2 && \
./configure --with-http_ssl_module --with-http_v2_module --prefix=/usr/local/nginx && \
make && make install && \
cd .. && \
rm -rf tengine-2.3.2.tar.gz tengine-2.3.2 && \
apt-get remove -y wget && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*
RUN npm install -g cnpm --registry=https://registry.npm.taobao.org
WORKDIR /app
COPY . .
RUN cnpm install
RUN npm run build
RUN cp -r dist/* /usr/local/nginx/html/
EXPOSE 80
CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]
```
这个 Dockerfile 中首先基于官方的 nginx 镜像构建了一个新的镜像,然后安装了 wget 工具,并下载、编译、安装了 tengine。
接着安装了 cnpm 工具,并将工作目录切换到 /app,将应用程序文件复制到容器中,并执行了 cnpm install 和 npm run build 命令来安装依赖和构建应用程序。
最后将构建好的应用程序文件复制到 /usr/local/nginx/html/ 目录下,并暴露了容器的 80 端口,并在 CMD 命令中启动了 nginx 服务。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)