Comment on page
Preparing Dockerfile for your model
This guide will help you to create Dockerfile for your model in easy steps.
Using Docker can help the users to easily deploy your AI model. The best way to understand the process is to look at actual Dockerfile and break it down. Here, we will look at the Dockerfile of 'Summer to Winter GAN' for reference.
1. FROM pytorch/pytorch
2. RUN apt-get update
3. RUN pip install certifi==2019.6.16 \
4. ENV PYTHONPATH /usr/local:/model/:$PYTHONPATH
5. WORKDIR /model
6. COPY . .
Don't use line numbers in actual Dockerfile.
Let's break it down 👇
FROM instruction defines the base image for your Dockerfile. In above Dockerfile we are using pytorch base image which itself uses ubuntu as base. If your model uses tensorflow, you can use
FROM tensorflow/tensorflowinstead or search for other available base images from dockerhub .
RUN apt-get update
RUN instruction lets you execute any command in your environment's CLI shell. Ex - If your model requires to install some additional package using apt-get , you can use -
RUN apt-get update && apt-get install -y \
<package 1> \
<package 2> \
Here RUN instruction is used to install pip packages.
ENV instruction allows to change environment variables. Most probably, you won't need ENV if you simply want to share model on Dockship.
As the name suggests, WORKDIR changes work directory. Think of it as 'cd' command's alternative for Docker .
COPY . .
COPY <src> <dest>copies content from your filesystem's \ to Docker's filesystem's \. In above example,
COPY . .copies whole directory content into Docker's filesystem.
Once you have created Dockerfile for your model, build its image and run container to verify if it's working properly.
docker build -t <model_name> -f Dockerfile <path_to_model_folder> && docker run -it <model_name>
Using the Dockerfile shared above as a template and making necessary changes will make the process much easier for you.