I am struggling to find a way to pass arguments to a python script within a docker container
based on ubuntu
. I am working with docker-compose.yml
.
Please find the example below!
docker-compose.yml
version: "3"
services:
bcp:
image: ubuntu:18.04
restart: always
tty: true
entrypoint: ["/bin/bash", "/ingestion/bcp-entrypoint.sh"]
volumes:
- ./services/bcp:/ingestion/services/bcp
- ./bcp-entrypoint.sh:/ingestion/bcp-entrypoint.sh
bcp-entrypoint.sh
apt-get update
apt-get upgrade -y
apt-get clean -y
apt-get install -y python3-pip
...
python script
required_args.add_argument("--database", metavar="str", type=str, help="database from where to extract", required=True)
The way I call the script - in container and on host machine - is python3 -m services.bcp --database foo
and it works just perfect. The question is, how can I achieve the same from host machine on docker container?
Basically, I am looking for something like docker-compose exec services.bcp --database foo
.
I do not want to use dockerfile
! Ideally everything is based on docker-compose
.
entrypoint:
array. (Though Compose may not be the tool you're looking for here.)entrypoint: ["/bin/bash", "/ingestion/bcp-entrypoint.sh", "python3 m", "boooo.py"]
?entrypoint.sh
knows how to handle a sub-command passed this way (maybe it ends withexec "$@"
) and you correctly break the command into words, that might work.bcp-entrypoint.sh
something likepython3 m --database $arg1
? And then I calldocker-compose exec bcp arg1=foo
? Then the question is how do I pass args to the entrypoint?