Dockerfile for Dockship🚀

Deepak Mangla
Dockship
Published in
2 min readNov 1, 2019

Hello world! 🙌

If you have an AI model that you want to share with the world🌍, Dockship is the place for you. In this article, I will help you create your own Dockerfile in easy steps to upload models on Dockship.

The best way to understand 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 \
chardet==3.0.4 \
dominate==2.4.0 \
idna==2.8 \
numpy==1.17.1 \
Pillow==6.1.0 \
pyzmq==18.1.0 \
requests==2.22.0 \
scipy==1.3.1 \
six==1.12.0 \
torch==1.2.0 \
torchfile==0.1.0 \
torchvision==0.4.0 \
tornado==6.0.3 \
urllib3==1.25.3 \
visdom==0.1.8.8 \
websocket-client==0.56.0 \
fire
4. ENV PYTHONPATH /usr/local:/model/:$PYTHONPATH
5. WORKDIR /model
6. COPY . .

⚠️ Warning: Don’t use line numbers in actual Dockerfile.

Let’s break it down 👇

Statement -1
FROM pytorch/pytorch

FROM instruction defines the base image for your Dockerfile.
In the above Dockerfile, we are using PyTorch base image which itself uses Ubuntu as a base.

If your model uses TensorFlow, you can use `FROM tensorflow/tensorflow` instead or search for other available base images from dockerhub .

Statement -2

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> \
<package 3>

Statement -3
Here RUN instruction is used to install pip packages.

Statement -4
ENV instruction allows for changing environment variables. Most probably, you won’t need ENV if you simply want to share the model on Dockship.

Statement -5
WORKDIR /model

As the name suggests, WORKDIR changes the work directory. Think of it as ‘cd’ command’s alternative for Docker.

Statement-6
COPY . .

`COPY <src> <dest>` copies content from your filesystem’s <src> to Docker’s filesystem’s <dest>.
In the above example, `COPY . .` copies whole directory content into Docker’s filesystem.

Test it yourself

Once you have created Dockerfile for your model, build its image and run the container to verify if it’s working properly.


docker build -t <model_name> -f Dockerfile <path_to_model_folder> && docker run -it <model_name>

Tip: Using Dockerfile shared above as a template and just making necessary changes will make the process much easier for you.🔥😀

All Aboard Dockship! 🚀

--

--