Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass json file as an argument using docker run command

Below is my Dockerfile content:

FROM python:2.7-slim

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

RUN pip install numpy==1.12.0

CMD ["python", "t_1.py", "t_1.json"]

I want to pass this file(t_1.sjon) as argument with docker run command at runtime so that CMD ["python", "t_1.py", "RUN TIME ARGUMENT"]. I tried mounting volumes but fails as json file is independent and I want as argument.

Please help.

like image 442
manzoor Avatar asked Feb 13 '26 22:02

manzoor


1 Answers

What you should use is ENTRYPOINT

FROM python:2.7-slim

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

RUN pip install numpy==1.12.0

ENTRYPOINT ["python", "t_1.py"]

Now when you run the docker command

docker run -v ./t_1.json:/data/t_1.json <dockerimage> /data/t_1.json

This will make it equivalent to python t_1.py /data/t_1.json

like image 166
Tarun Lalwani Avatar answered Feb 15 '26 11:02

Tarun Lalwani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!