skip to Main Content

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

3

Answers


  1. 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

    Login or Signup to reply.
    • 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search