diff --git a/podman_compose.py b/podman_compose.py index 8116863..f483390 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -1227,7 +1227,6 @@ def compose_ps(compose, args): @cmd_run(podman_compose, 'run', 'create a container similar to a service to run a one-off command') def compose_run(compose, args): create_pods(compose, args) - print(args) container_names=compose.container_names_by_service[args.service] container_name=container_names[0] cnt = compose.container_by_name[container_name] @@ -1241,6 +1240,11 @@ def compose_run(compose, args): if args.entrypoint: cnt["entrypoint"] = args.entrypoint if args.user: cnt["user"] = args.user if args.workdir: cnt["working_dir"] = args.workdir + env = dict(cnt.get('environment', {})) + if args.env: + additional_env_vars = dict(map(lambda each: each.split('='), args.env)) + env.update(additional_env_vars) + cnt['environment'] = env if not args.service_ports: for k in ("expose", "publishall", "ports"): try: del cnt[k] @@ -1375,7 +1379,7 @@ def compose_run_parse(parser): help="Assign a name to the container") parser.add_argument("--entrypoint", type=str, default=None, help="Override the entrypoint of the image.") - parser.add_argument('-e', metavar="KEY=VAL", action='append', + parser.add_argument('-e', '--env', metavar="KEY=VAL", action='append', help="Set an environment variable (can be used multiple times)") parser.add_argument('-l', '--label', metavar="KEY=VAL", action='append', help="Add or override a label (can be used multiple times)") diff --git a/tests/env-tests/README.md b/tests/env-tests/README.md new file mode 100644 index 0000000..b1c96cf --- /dev/null +++ b/tests/env-tests/README.md @@ -0,0 +1,5 @@ +running the following command should give myval2 + +``` +podman_compose run -l monkey -e ZZVAR1=myval2 env-test +``` diff --git a/tests/env-tests/container-compose.yml b/tests/env-tests/container-compose.yml new file mode 100644 index 0000000..ba39c3f --- /dev/null +++ b/tests/env-tests/container-compose.yml @@ -0,0 +1,9 @@ +version: '3' + +services: + env-test: + image: busybox + command: sh -c "export | grep ZZ" + environment: + - ZZVAR1=myval1 +