I made a python script to update json file. code is look like this:-
with open('config.json') as config_file:
data = json.load(config_file)
Device_ID = data['id']
Device_API = data['API']
if Device_ID=='':
time.sleep(2)
Device_id = str(input("Enter Device ID:"))
Device_details = {"id": "",
"API": ""}
Device_API = "https://api.com/"
Device_details["id"] = Device_id
Device_details["API"]=Device_API
Device_ID=Device_id
with open('config.json', 'w') as json_file:
json.dump(Device_details, json_file)
json_file.close()
and I write docker file to make docker, here it is:-
FROM python:3.6
CMD apt-get install python3-dev
COPY PingStatus.py .
COPY config.json .
CMD python3 PingStatus.py
Now I used 'docker run -i mycode' command to run image. ( I faced EOF error so I used '-i') and its working good.
My config.json file look like this
so, whenever I build docker and run the docker it will ask for Device_Id, but whenever I run the docker again it keep asking for the same, I can not understand the issue. but I made a code that update the existing json file,then why it keep asking for device id.
I try to run script only and it working properly. Like it is asking for device id first time but after first attempt, every time it will take device id from json file.
I understand that my python script is not updating json file while running inside docker image/container.
As @Hack5 Said and suggested, We need to copy config file while creating docker image. I have two variables that needs to be set in config file so I made both of them constant and it solved my problem. Thanks @Hack5.