Use a single dockerfile to start many docker containers [closed]

I have a docker image called testapps and this single image has 5 tiny webapps, for now we will call them apps A through E. I'd like to deploy this single image and create a dockerfile that instantiates a container for each app so that when I run:

docker build -t apps . 

I expect 5 containers and each container is running a different app.

My first question is, how do I reference a locally stored image (saved using command docker save pesky_perk -o testapps) in a dockerfile?

Secondly, How do I use the referenced docker image to instantiate 5 containers based off of one image, each with it's own Entry point like:

#Container 1
ENTRYPOINT ["java", "-jar", "/A.jar"]
#Container 2
ENTRYPOINT ["java", "-jar", "/B.jar"]
#Container 3
ENTRYPOINT ["java", "-jar", "/C.jar"]
#Container 4
ENTRYPOINT ["java", "-jar", "/D.jar"]
#Container 5
ENTRYPOINT ["java", "-jar", "/E.jar"]


Solution 1:

A Dockerfile doesn't instantiate containers. It just builds images. If you want to use the same image to run multiple apps, just include the relevant commands on the docker run command line:

docker run --name app_A myimage /A.jar
docker run --name app_B myimage /B.jar
docker run --name app_C myimage /C.jar
docker run --name app_D myimage /D.jar
docker run --name app_E myimage /E.jar

This assumes your Dockerfile contains:

ENTRYPOINT ["java", "-jar"]

The FROM line in a Dockerfile always refers to a local image: if it doesn't exist locally, it is pulled from a remote repository. But if it matches an available local image, you're all set.

If you have the output of docker save, you would need to docker load it first so that your local Docker daemon was aware of it.