0

I created a docker image to run some scripts. I copy 2 Python scripts into my Docker image. The end of my Dockerfile looks like this.

COPY . /app
ENTRYPOINT ["python3"]

When I want to run it using Docker I simply run

Docker run -i image_name script1.py ... -other -flags

or

Docker run -i image_name script2.py ... -other -flags

I'd like to be able to do something similar thing using Apptainer.

I've looked at these commands in Apptainer.

apptainer shell <container>
apptainer exec <container> <command>
apptainer run <container>
apptainer instance start <container> [name]

But when I try to run script1.py or script2.py, they aren't found.

Is there a way to do this without re-writing the image with Apptainer?

Sam H
  • 45
  • 4
  • Docker is supporting you to containerize things, and as in your example, you're containerized your scripts into the container. So when the container is running, you code will be there. But: - You have to understand WORKDIR in Docker - You also have to understand the foreground process for the container With those, you will know how to exec a python script from a container. docker run -i image_name python your_codebase_location – Toan Quoc Ho Aug 11 '23 at 19:23
  • (I would probably remove that `ENTRYPOINT` line. Assuming your scripts are executable and start with a "shebang" line `#!/usr/bin/env python3` then you can just directly run `./script1.py` without explicitly saying `python3`; the `ENTRYPOINT` can lead to some syntactic confusion, potentially even related to the question you're asking.) – David Maze Aug 11 '23 at 20:07

0 Answers0