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....rbwhen 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.rbandb/b.rb.That means the Dockerfile has 2
COPYdirectives, to include those scripts.Since you want only one Dockerfile, producing one image, you should include in it a
COPY start.shscript andCMD start.shdirective. That script (now included in the image) which would runa/r.rborb/r.rbdepending on an environment variable (for exampleMUSTRUN).Keep it mind your container will stop once the
r.rbscript exits.To keep it running, you would need to change the
start.shin order to loop indefinitely, a bit like "A Daemonized Hello world".