我有一个自定义bash脚本,我想将其复制到Dockfile中的docker-entrypoint.sh。
我的docker文件
# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# production stage
FROM nginx:latest as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY ./entrypoint.sh /entrypoint.sh
RUN /entrypoint.sh >> docker-entrypoint.sh
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
我的entrypoint.sh文件
#!/bin/sh
JSON_STRING='window.configs = {
"GLOBAL_VAR":"'"${GLOBAL_VAR}"'",
}'
sed -i "s@// CONFIGURATIONS_PLACEHOLDER@${JSON_STRING}@" /usr/share/nginx/html/index.html
exec "$@"
如何将自定义入口点.sh复制到docker-entrypoint.sh
当nginx容器启动时,位于/docker-entrypoint.d
文件夹中的所有.sh文件都会执行。您可以将.sh文件放在/docker-entrypoint.d
文件夹中,并设置他+x权限,而不是将行添加到docker-entrypoint.sh文件中。
COPY YOUR_SCRIPT.sh /docker-entrypoint.d/
RUN chmod +x /docker-entrypoint.d/YOUR_SCRIPT.sh