Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add a path to PYTHONPATH in a Dockerfile

How do you add a path to PYTHONPATH in a Dockerfile? So that when the container is run it has the correct PYTHONPATH? I'm completely new to Docker.

I've added ENV PYTHONPATH "${PYTHONPATH}:/control" to the Dockerfile as I want to add the directory /control to PYTHONPATH.

When I access the container's bash with docker exec -it trusting_spence bash and open python and run the commands below the directory control is not on the list.

import sys print(sys.path)

FROM python:2 RUN pip install requests pymongo  RUN mkdir control  COPY control_file/ /control  ENV PYTHONPATH "${PYTHONPATH}:/control"  CMD ["python","control/control_file/job.py"]  
like image 301
arcoxia tom Avatar asked Apr 03 '18 13:04

arcoxia tom


People also ask

What is mkdir in Dockerfile?

RUN mkdir -p /var/www/html/foo creates the foo directory inside the filesystem of your container. docker-compose. yml ./code:/var/www/html "hides" the content of /var/www/html in the container filesystem behind the contents of ./code on the host filesystem.


Video Answer


1 Answers

Just add an ENV entry in your Dockerfile:

ENV PYTHONPATH "${PYTHONPATH}:/your/custom/path" 

Or set PYTHONPATH in your startup script.

like image 86
Erik Cederstrand Avatar answered Sep 22 '22 20:09

Erik Cederstrand