Skip to content

Instantly share code, notes, and snippets.

@i-amgeek
Last active November 1, 2019 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i-amgeek/1e0c7633bb720790753a408dbca6c08f to your computer and use it in GitHub Desktop.
Save i-amgeek/1e0c7633bb720790753a408dbca6c08f to your computer and use it in GitHub Desktop.
Creating Dockerfile for Dockship

Creating Dockerfile for Dockship

Hello world 🙌

If you have an AI model which 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 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 above Dockerfile we are using pytorch base image which itself uses ubuntu as 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 to change environment variables. Most probably, you won't need ENV if you simply want to share model on Dockship.

Statement -5

WORKDIR /model

As the name suggests, WORKDIR changes 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 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 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.
:fire::grin:

All Aboard Dockship! :rocket:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment