Docker run throws error executable file not found in $PATH when arguments are passed

5 days ago 7
ARTICLE AD BOX

I Have a python program which I containerized. The script accepts command line arguments. Arguments are correctly processed when running the script directly from the IDE. But if I run the container with arguments it throws error. Works fine without command line args.

Here is the python script entry:

async def main(): arg_parser = argparse.ArgumentParser() arg_parser.add_argument('--config_file', type=str, default='config.json') arg_parser.add_argument('--log_dir', type=str, default='log') arg_parser.add_argument('--out_dir', type=str, default='out') args = arg_parser.parse_args()

Here is my Docker file:

# Use an official Python runtime as a parent image FROM python:3.12-slim # Set the working directory in the container WORKDIR /root # Copy the requirements file and install dependencies COPY requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the application code into the container COPY app/ /root/app # Command to run the Python script when the container starts CMD ["python", "app/main.py"]

Here is the docker run:

sudo docker run --network=host -v /home/<user>/host:/root/host -v /etc/localtime:/etc/localtime:ro myapp --config_file a.json

which throws:

docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: exec: "--config_file a.json": executable file not found in $PATH

What am I missing?

Read Entire Article