Course Wiki

Environment management: Docker — Machine Learning Zoomcamp Module 5

- Once our project was packed in a Docker container, we're able to run our project on any machine. - First we have to make a Docker image. In Docker image file there are settings and dependecies we have in our project. To find Docker...

Machine Learning Zoomcamp › Module 5: Deploying Machine Learning Models › Environment management: Docker

Notes

Here a Dockerfile (There should be no comments in Dockerfile, so remove the comments when you copy)

# First install the python 3.8, the slim version uses less space
FROM python:3.8.12-slim
# Install pipenv library in Docker 
RUN pip install pipenv

# create a directory in Docker named app and we're using it as work directory 
WORKDIR /app                                                                
# Copy the Pip files into our working derectory 
COPY ["Pipfile", "Pipfile.lock", "./"]
# install the pipenv dependencies for the project and deploy them.
RUN pipenv install --deploy --system
# Copy any python files and the model we had to the working directory of Docker 
COPY ["*.py", "churn-model.bin", "./"]
# We need to expose the 9696 port because we're not able to communicate with Docker outside it
EXPOSE 9696
# If we run the Docker image, we want our churn app to be running
ENTRYPOINT ["gunicorn", "--bind=0.0.0.0:9696", "churn_serving:app"]

The flags --deploy and --system make sure that we install the dependencies directly inside the Docker container without creating an additional virtual environment (which pipenv does by default).

If we don’t put the last line ENTRYPOINT, we will be in a python shell. Note that for the entrypoint, we put our commands in double quotes.

After creating the Dockerfile, we need to build it:

docker build -t churn-prediction .

To run it, execute the command below:

docker run -it -p 9696:9696 churn-prediction:latest

Flag explanations:

At last you’ve deployed your prediction app inside a Docker container. Congratulations 🥳

⚠️ The notes are written by the community.
If you see an error here, please create a PR with a fix.

Key concepts

Sources


DataTalks.Club. Hosted on GitHub Pages. Built with Rustkyll. We use cookies.