I want to launch hundreds of container with one command.
Container A will change directory to a
then run a.rb
when it is launched
Container B will change directory to b
then run b.rb
when it is launched
Container ... will change directory to
...
then run....rb
when it is launched
All of those containers should share the same Dockerfile.
I need to switch to correspoding folder then execute script
But I got error
failed to exec: exec: "cd": executable file not found in $PATH
a:
build: .
command: cd a ; ruby a.rb
volumes:
- .:/crawler
ports:
- 5901:5901
b:
build: .
command: cd b ; ruby b.rb
volumes:
- .:/crawler
ports:
- 5902:5902
First, the image built from the Dockerfile must include
a/r.rb
andb/b.rb
.That means the Dockerfile has 2
COPY
directives, to include those scripts.Since you want only one Dockerfile, producing one image, you should include in it a
COPY start.sh
script andCMD start.sh
directive. That script (now included in the image) which would runa/r.rb
orb/r.rb
depending on an environment variable (for exampleMUSTRUN
).Keep it mind your container will stop once the
r.rb
script exits.To keep it running, you would need to change the
start.sh
in order to loop indefinitely, a bit like "A Daemonized Hello world".