如何保留之前 Docker 阶段的文件
我有两个 dockerfile,用于构建部署为 AWS Lambda 的 docker 映像。我想在最终构建的 docker 映像中保留 docker image amazon/aws-lambda-python:3.9 中的文件。我构建了公共 docker 镜像并将其发布到 docker hub 上。
当我在本地构建此 docker 映像时,一切都按预期进行。
但是,当我使用 Bitbucket 管道构建从公共 docker 映像拉取的私有 dockerfile 时,许多基本文件在最后的构建步骤。
我需要将 amazon/aws-lambda-python:3.9 中的整个 /var 文件夹作为 aws 包含在我的最终 docker 映像中。我怎样才能实现这个目标?
公共 docker 镜像:
FROM amazon/aws-lambda-python:3.9 as aws
ENV PATH=/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin
ENV LAMBDA_RUNTIME_DIR=/var/runtime
ENV LANG=en_US.UTF-8
ENV TZ=:/etc/localtime
ENV LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib
ENV LAMBDA_TASK_ROOT=/var/task
ENV LAMBDA_RUNTIME_DIR=/var/runtime
RUN yum update -y
RUN yum -y install tesseract poppler-utils
RUN python3 -m pip install --upgrade pip
RUN pip3 install pillow pytesseract requests boto3 python-dotenv pytz gql[all] PyMuPDF google-cloud-storage pdf2image --target "${LAMBDA_TASK_ROOT}"
WORKDIR ${LAMBDA_TASK_ROOT}
ENTRYPOINT [ "/lambda-entrypoint.sh" ]
私有 docker 镜像:
FROM private-docker-image:latest
ENV PATH=/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin
ENV LAMBDA_RUNTIME_DIR=/var/runtime
ENV LANG=en_US.UTF-8
ENV TZ=:/etc/localtime
ENV LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib
ENV LAMBDA_TASK_ROOT=/var/task
ENV LAMBDA_RUNTIME_DIR=/var/runtime
COPY --from=amazon/aws-lambda-python:3.9 / /
COPY . ${LAMBDA_TASK_ROOT}
WORKDIR ${LAMBDA_TASK_ROOT}
RUN chmod -R +rwx ${LAMBDA_TASK_ROOT}
RUN chmod +x /lambda-entrypoint.sh
ENTRYPOINT [ "start.sh" ]
CMD [ "app.handler" ]
I have two dockerfiles that I use to build a docker image that's deployed as a AWS Lambda. and I would like to retain the files from docker image amazon/aws-lambda-python:3.9 in my final built docker image. I build the public docker image and publish it on docker hub.
When I build this docker image locally everything is as expected.
However, when I use Bitbucket pipelines to build my private dockerfile pulling from my public docker image, many of the essential files are missing in the final build step.
I need the entire /var folder from amazon/aws-lambda-python:3.9 as aws to be in my final docker image. How can I achieve this?
Public docker image:
FROM amazon/aws-lambda-python:3.9 as aws
ENV PATH=/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin
ENV LAMBDA_RUNTIME_DIR=/var/runtime
ENV LANG=en_US.UTF-8
ENV TZ=:/etc/localtime
ENV LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib
ENV LAMBDA_TASK_ROOT=/var/task
ENV LAMBDA_RUNTIME_DIR=/var/runtime
RUN yum update -y
RUN yum -y install tesseract poppler-utils
RUN python3 -m pip install --upgrade pip
RUN pip3 install pillow pytesseract requests boto3 python-dotenv pytz gql[all] PyMuPDF google-cloud-storage pdf2image --target "${LAMBDA_TASK_ROOT}"
WORKDIR ${LAMBDA_TASK_ROOT}
ENTRYPOINT [ "/lambda-entrypoint.sh" ]
Private docker image:
FROM private-docker-image:latest
ENV PATH=/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin
ENV LAMBDA_RUNTIME_DIR=/var/runtime
ENV LANG=en_US.UTF-8
ENV TZ=:/etc/localtime
ENV LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib
ENV LAMBDA_TASK_ROOT=/var/task
ENV LAMBDA_RUNTIME_DIR=/var/runtime
COPY --from=amazon/aws-lambda-python:3.9 / /
COPY . ${LAMBDA_TASK_ROOT}
WORKDIR ${LAMBDA_TASK_ROOT}
RUN chmod -R +rwx ${LAMBDA_TASK_ROOT}
RUN chmod +x /lambda-entrypoint.sh
ENTRYPOINT [ "start.sh" ]
CMD [ "app.handler" ]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论