如何将复制文件添加到Docker映像
我正在运行一个Python脚本来操纵图片。当我运行测试时,系统显然找不到图像。我是Docker的新手,并不真正了解该怎么做。
这是Dockerfile
FROM ubuntu:latest
RUN apt update
RUN apt install python3 -y
RUN apt-get -y install python3-pip
RUN pip install pillow
RUN pip install wand
RUN DEBIAN_FRONTEND="noninteractive" apt-get install libmagickwand-dev --no-install-recommends -y
WORKDIR /usr/app/src
COPY image_converter.py ./
COPY test_image_converter.py ./
RUN python3 -m unittest test_image_converter.py
I'm running a python script to manipulate pictures. When I run the test the system obviously does not find the images. I new to docker and don't really understand how to do that.
This is how the structure looks
And this is the dockerfile
FROM ubuntu:latest
RUN apt update
RUN apt install python3 -y
RUN apt-get -y install python3-pip
RUN pip install pillow
RUN pip install wand
RUN DEBIAN_FRONTEND="noninteractive" apt-get install libmagickwand-dev --no-install-recommends -y
WORKDIR /usr/app/src
COPY image_converter.py ./
COPY test_image_converter.py ./
RUN python3 -m unittest test_image_converter.py
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这里,您复制
****。py
文件./
(==workdir
),所以 的方式将图像文件复制到
workdir
等
以相同
here you've COPIED
****.py
file to./
(==WORKDIR
)so, in the same way copy your image files to your
WORKDIR
such as
This should work
IDK如果这会有所帮助,但请尝试查看其内容。
https://www.geeksforgeeks.orgss.org/复制文件 - 直到docker-containers/
IDK if this will help, but try to look its content.
https://www.geeksforgeeks.org/copying-files-to-and-from-docker-containers/
首先,您没有复制图像文件夹,应具有以下命令:
workdir/usr/app/src
复制test_images ./
第二,您应该结合相同类型的docker命令(要减少图层,因此减少了Docker Image的大小)
示例:而不是说
复制image_converter.py ./
复制test_image_converter.py ./
您可以编写
另一个示例:
运行apt Update run
apt apt apt aint python3 -y
可以编写
First, you didn't copy the image folder, should have these commands:
WORKDIR /usr/app/src
COPY test_images ./
Second, you should combine same type of Docker commands (to reduce layers, hence reduce docker image's size)
example : instead of saying
COPY image_converter.py ./
COPY test_image_converter.py ./
You can write
Another example :
RUN apt update
RUN apt install python3 -y
You can write