Open 499689317 opened 7 years ago
# centos7镜像 FROM centos
# 安装node v6.10.1 RUN yum install -y wget
# 使用淘宝镜像安装Node.js v6.10.1 RUN wget https://npm.taobao.org/mirrors/node/v6.10.1/node-v6.10.1-linux-x64.tar.gz && \ tar -C /usr/local --strip-components 1 -xzf node-v6.10.1-linux-x64.tar.gz && \ rm node-v6.10.1-linux-x64.tar.gz
WORKDIR /app
# 安装npm模块 ADD package.json /app/package.json
# 使用淘宝的npm镜像 RUN npm install --production -d --registry=https://registry.npm.taobao.org
# 添加源代码 ADD . /app
# 运行app.js CMD ["node", "/app/app.js"]
libstdc++版本不是特别兼容这个版本的node,具体问题需要追踪
FROM node
WORKDIR /home/mod
COPY package.json ./
RUN npm install --production -d --registry=https://registry.npm.taobao.org
FROM alpine:3.9
USER root
RUN apk update
strings /usr/lib/libstdc++.os.6 | grep GLIBC
RUN apk add --no-cache --update libstdc++
ENV GLIBC_VERSION=2.27-r0
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/sgerrand.rsa.pub \ && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk \ && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-bin-${GLIBC_VERSION}.apk \ && apk --no-cache add glibc-${GLIBC_VERSION}.apk \ && apk --no-cache add glibc-bin-${GLIBC_VERSION}.apk \ && rm glibc-${GLIBC_VERSION}.apk \ && rm glibc-bin-${GLIBC_VERSION}.apk
ENV NODE_VERSION=v12.10.0 RUN wget https://cdn.npm.taobao.org/dist/node/${NODE_VERSION}/node-${NODE_VERSION}-linux-x64.tar.gz \ && tar -xf node-${NODE_VERSION}-linux-x64.tar.gz --directory /usr/local --strip-components 1 \ && rm node-${NODE_VERSION}-linux-x64.tar.gz
RUN apk del wget tar
RUN ln -s /usr/local/bin/node /usr/bin/node
ENV PATH "/usr/local/bin:${PATH}"
RUN echo "PATH env variable => '$PATH'"
COPY --from=0 /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib/
WORKDIR /nodejs/web
COPY --from=0 /home/mod/node_modules ./node_modules
COPY . .
CMD ["node", "app.js"]
busybox:glibc有一个问题,还是缺少了很多动态库文件
FROM debian:stable as builder
FROM busybox:glibc
COPY --from=builder /lib/x86_64-linux-gnu/librt.so.1 /lib COPY --from=builder /lib/x86_64-linux-gnu/libdl.so.2 /lib
RUN wget https://cdn.npm.taobao.org/dist/node/v12.10.0/node-v12.10.0-linux-x64.tar.gz && \ tar -xf node-v12.10.0-linux-x64.tar.gz --directory /usr --strip-components 1 && \ rm node-v12.10.0-linux-x64.tar.gz
ENV PATH "/usr/local/bin:${PATH}" RUN echo "PATH env variable => '$PATH'"
事例
# centos7镜像 FROM centos
# 安装node v6.10.1 RUN yum install -y wget
# 使用淘宝镜像安装Node.js v6.10.1 RUN wget https://npm.taobao.org/mirrors/node/v6.10.1/node-v6.10.1-linux-x64.tar.gz && \ tar -C /usr/local --strip-components 1 -xzf node-v6.10.1-linux-x64.tar.gz && \ rm node-v6.10.1-linux-x64.tar.gz
WORKDIR /app
# 安装npm模块 ADD package.json /app/package.json
# 使用淘宝的npm镜像 RUN npm install --production -d --registry=https://registry.npm.taobao.org
# 添加源代码 ADD . /app
# 运行app.js CMD ["node", "/app/app.js"]
版本一
libstdc++版本不是特别兼容这个版本的node,具体问题需要追踪
FROM node
WORKDIR /home/mod
COPY package.json ./
RUN npm install --production -d --registry=https://registry.npm.taobao.org
FROM alpine:3.9
USER root
RUN apk update
RUN apk add --no-cache libgcc
安装libstdc++会自动安装libgcc,但是apk下安装的libstdc++是不完整的动态文件(很奇怪)
strings /usr/lib/libstdc++.os.6 | grep GLIBC
发现动态库文件不完整,为什么呢?RUN apk add --no-cache --update libstdc++
RUN apk add --no-cache --update wget
RUN apk add --no-cache tar
2.23-r3
ENV GLIBC_VERSION=2.27-r0
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/sgerrand.rsa.pub \ && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk \ && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-bin-${GLIBC_VERSION}.apk \ && apk --no-cache add glibc-${GLIBC_VERSION}.apk \ && apk --no-cache add glibc-bin-${GLIBC_VERSION}.apk \ && rm glibc-${GLIBC_VERSION}.apk \ && rm glibc-bin-${GLIBC_VERSION}.apk
12.10.0
ENV NODE_VERSION=v12.10.0 RUN wget https://cdn.npm.taobao.org/dist/node/${NODE_VERSION}/node-${NODE_VERSION}-linux-x64.tar.gz \ && tar -xf node-${NODE_VERSION}-linux-x64.tar.gz --directory /usr/local --strip-components 1 \ && rm node-${NODE_VERSION}-linux-x64.tar.gz
RUN apk del wget tar
RUN ln -s /usr/local/bin/node /usr/bin/node
RUN ln -s /usr/local/bin/npm /usr/bin/npm
ENV PATH "/usr/local/bin:${PATH}"
RUN echo "PATH env variable => '$PATH'"
COPY --from=0 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 /lib/
直接把builder的libstdc++动态库拷贝到镜像中,暴力解决
COPY --from=0 /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib/
RUN ln -s /lib/libstdc++.so.6.0.22 /lib/libstdc++.so.6
WORKDIR /nodejs/web
COPY --from=0 /home/mod/node_modules ./node_modules
COPY . .
CMD ["node", "app.js"]
版本二
busybox:glibc有一个问题,还是缺少了很多动态库文件
FROM debian:stable as builder
FROM busybox:glibc
USER root
COPY --from=builder /lib/x86_64-linux-gnu/librt.so.1 /lib COPY --from=builder /lib/x86_64-linux-gnu/libdl.so.2 /lib
RUN wget https://cdn.npm.taobao.org/dist/node/v12.10.0/node-v12.10.0-linux-x64.tar.gz && \ tar -xf node-v12.10.0-linux-x64.tar.gz --directory /usr --strip-components 1 && \ rm node-v12.10.0-linux-x64.tar.gz
ENV PATH "/usr/local/bin:${PATH}" RUN echo "PATH env variable => '$PATH'"