0

I want to build a Docker image to run a Python script. I added some files to the image during the building process and installed some python packages.

In the last line of my Dockerfile I have:

CMD ["python3", "script.py"]

I aim to run this script using the container, but I must provide some input files before running it. Building the image takes some time because I'm adding some large files, so I want to avoid building the image and moving the input files whenever I want to run the script.

Is it possible to do this?

I tried using docker create and then copying the files with cp, but I don't know how to run the container recently created.

I'm trying to work from this post https://stackoverflow.com/a/48265968/19257725

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

docker cp copies files to (and from) containers. And as you shared, you may create a non-running container with docker create, copy your files with docker cp then run the container with:

# Example from: https://docs.docker.com/engine/reference/commandline/create/#create-and-start-a-container
docker container start --attach -i mycontainer

Replace mycontainer with your container name.


However this may cause Docker to kill your container due to OOM if you have large files, for this I recommend using docker volumes, so you would run your container and attach a volume that reads the files from your disk directly, with this you would have a lighter Docker container, and you can ship lighter images, and make data downloadable separately if you want to publish it.

Read more:

Fcmam5
  • 4,888
  • 1
  • 16
  • 33