如何将复制文件添加到Docker映像

发布于 2025-02-08 10:54:17 字数 654 浏览 1 评论 0原文

我正在运行一个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
enter image description here

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 技术交流群。

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

发布评论

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

评论(3

や莫失莫忘 2025-02-15 10:54:17
COPY image_converter.py ./
COPY test_image_converter.py ./

在这里,您复制 ****。py文件./(== workdir

,所以 的方式将图像文件复制到workdir

COPY test_images ./

以相同

COPY image_converter.py ./
COPY test_image_converter.py ./

here you've COPIED ****.py file to ./(== WORKDIR)

so, in the same way copy your image files to your WORKDIR

such as

COPY test_images ./

This should work

椵侞 2025-02-15 10:54:17

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/

好听的两个字的网名 2025-02-15 10:54:17
  • 首先,您没有复制图像文件夹,应具有以下命令:

    workdir/usr/app/src

    复制test_images ./

  • 第二,您应该结合相同类型的docker命令(要减少图层,因此减少了Docker Image的大小)
    示例:而不是说

    复制image_converter.py ./

    复制test_image_converter.py ./

您可以编写

COPY *.py ./

另一个示例:

运行apt Update run

apt apt apt aint python3 -y

可以编写

运行APT更新; APT安装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

COPY *.py ./

Another example :

RUN apt update

RUN apt install python3 -y

You can write

RUN apt update; apt install python3 -y

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