The second half of the Dockerfile (set the default value of the environment variable, and pass it to run.sh)
A pit: The form of [] cannot be used after ENTRYPOINT, otherwise the environment cannot be readvariable.
# set environment defaultsENV task_id=123ENV task_param=1# entrypoint is the container entry # The following [] form cannot be used, otherwise the environment variable cannot be read!!# ENTRYPOINT ["/bin/bash", "/code/run.sh"]ENTRYPOINT /bin/bash /code/run.sh $task_id $task_param
Used to output the passed environment variables, used to verify whether the environment variables are valid; and execute the python script
echo "task_id = ${task_id}"echo "task_param = ${task_param}"python /code/main.py
python script, use os.environ
to read environment variables.
import ostask_id = os.environ['task_id']task_param = os.environ['task_param']
Build the image: docker build -t image_name:v1.211020 -f ./Dockerfile .
Build the container and run: docker run -e task_id="ua084d" -etask_param={"tag": "BERT"} --name MO_CLS_ua084d 9c6ad6da --rm
A pit I stepped on here:
Note: The -e parameter of docker run must follow run, otherwise it will not take effect!!
Note: The -e parameter of docker run must follow run, otherwise it will not take effect!!
Note: The -e parameter of docker run must follow run, otherwiseNot valid!!