Search code examples
pythondockermesos

How to write a Dockerfile for a custom python project?


I'm pretty new to Docker, and I need to create the container to run Docker container as an Apache Mesos task.

The problem is that I can't find any relevant examples. They all are centered around Web development, which is not my case.

I have a pure Python project with large number of dependencies ( like Berkeley Caffe or OpenCV ). How to write a Docker file to properly enroll all dependecies ( and how to find them out?)


Solution

  • The docker hub registry contains a number of official language images, which you can use as your base image.

    The instructions tell you how you can build your python project, including the importation of dependencies.

    ├── Dockerfile                <-- Docker build file
    ├── requirements.txt          <-- List of pip dependencies
    └── your-daemon-or-script.py  <-- Python script to run
    

    Image supports both Python 2 and 3, you specify this in the Dockerfile:

    FROM python:3-onbuild
    CMD [ "python", "./your-daemon-or-script.py" ]
    

    The base image uses special ONBUILD instructions to all the hard work for you.