了解Docker:我的Docker容器内容如何动态?

发布于 2025-02-01 13:56:00 字数 592 浏览 2 评论 0原文

我想确保我正确理解docker:当我从当前目录中构建图像时:在构建

docker build -t imgfile .

图像后,当我更改目录中文件的内容时会发生什么?根据我的尝试,似乎它也动态地改变了Docker映像的内容。 我认为Docker映像就像一个邮政编码文件,只能使用Docker命令更改或登录图像和运行命令。

Dockerfile是:

FROM lambci/lambda:build-python3.8
WORKDIR /var/task
EXPOSE 8000
RUN echo 'export PS1="\[\e[36m\]zappashell>\[\e[m\] "' >> /root/.bashrc
CMD ["bash"]

而且Docker Run命令是:

docker run -ti -p 8000:8000 -e AWS_PROFILE=zappa -v "$(pwd):/var/task" -v ~/.aws/:/root/.aws --rm zappa-docker-image

谢谢,

最好,

I want to make sure I understand correctly docker: when i build an image from the current directory I run:

docker build -t imgfile .

What happens when i change the content of a file in the directory AFTER the image is built? From what i've tried it seems it changes the content of the docker image also dynamically.
I thought the docker image was like a zip file that could only be changed with docker commands or logging into the image and running commands.

The dockerfile is :

FROM lambci/lambda:build-python3.8
WORKDIR /var/task
EXPOSE 8000
RUN echo 'export PS1="\[\e[36m\]zappashell>\[\e[m\] "' >> /root/.bashrc
CMD ["bash"]

And the docker run command is :

docker run -ti -p 8000:8000 -e AWS_PROFILE=zappa -v "$(pwd):/var/task" -v ~/.aws/:/root/.aws --rm zappa-docker-image

Thank you

Best,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声静候 2025-02-08 13:56:00

您的Docker Run命令根本没有真正运行您的图像。 docker run -v $(pwd):/var/task语法覆盖图像中/var/task ocy> in

您是对的,图像是不变的。您显示的图像实际上不包含任何东西,除了.bashrc通常不会使用的文件。您可以尝试在没有-v选项的情况下运行图像,

docker run --rm zappa-docker-image ls -al
# just shows `.` and `..` directories

请确保您复制您的应用程序将其应用于图像,设置其cmd 实际运行该应用程序,并删除覆盖其主要目录的-v选项。如果您的目标是针对主机文件运行主机代码,并使用主机支持您的AWS凭据(例如AWS凭据),那么您并没有从应用程序和使用它使用的每个文件之间介绍Docker真正的好处。

Your docker run command isn't really running your image at all. The docker run -v $(pwd):/var/task syntax overwrites what was in /var/task in the image with a bind mount to the current directory on the host. So when you edit a file on your host, the container has the same host directory (and not the content from the image) and you see the changes inside the container as well.

You're right that the image is immutable. The image you show doesn't really contain anything, beyond a .bashrc file that won't usually be used. You can try running the image without the -v options to see:

docker run --rm zappa-docker-image ls -al
# just shows `.` and `..` directories

I'd recommend making sure you COPY your application into the image, setting its CMD to actually run the application, and removing the -v option that overwrites its main directory. If your goal is to run host code against host files with host supporting data like your AWS credentials, you're not really getting much benefit from introducing Docker in between your application and every single file it uses.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文