了解Docker:我的Docker容器内容如何动态?
我想确保我正确理解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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
Docker Run
命令根本没有真正运行您的图像。docker run -v $(pwd):/var/task
语法覆盖图像中/var/task ocy> in
您是对的,图像是不变的。您显示的图像实际上不包含任何东西,除了
.bashrc
通常不会使用的文件。您可以尝试在没有-v
选项的情况下运行图像,请确保您
复制
您的应用程序将其应用于图像,设置其cmd 实际运行该应用程序,并删除覆盖其主要目录的
-v
选项。如果您的目标是针对主机文件运行主机代码,并使用主机支持您的AWS凭据(例如AWS凭据),那么您并没有从应用程序和使用它使用的每个文件之间介绍Docker真正的好处。Your
docker run
command isn't really running your image at all. Thedocker 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:I'd recommend making sure you
COPY
your application into the image, setting itsCMD
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.