Search code examples
pythondockerdocker-composelocust

Docker Locust locustfile.py not found


I need to create an image from https://hub.docker.com/r/locustio/locust that contains the locustfile.py.

I use this Dockerfile:

FROM locustio/locust:1.1.1
ADD locustfile.py /mnt/locust
RUN pip3 install ...

Then I build the image:

docker build -t mylocustimage locust/.

And I try to use it in my docker-compose.yml:

locust-master:
    image: mylocustimage
    ports:
      - "8089:8089"
    command: -f /mnt/locust/locustfile.py -H http://localhost --logfile=locustfile.log

But every time I try to start the container it fails with this error:

Could not find any locustfile! Ensure file ends in '.py' and see --help for available options.

Could someone help me figure out what I'm doing wrong?


Solution

  • You're missing the trailing slash, you need to do:

    ADD locustfile.py /mnt/locust/
    

    ... otherwise locustfile.py will be saved to the image as literally /mnt/locust instead of /mnt/locust/locustfile.py