How to Run Google TensorFlow on Alibaba Cloud

By Nikesh Gogia, Solution Architect

This tutorial is targeted for any organization that wants to host TensorFlow on Alibaba Cloud using Docker containers. This document can be used by Solution Architects or Business Development teams for proof of concept (POC) of any customer requirement and gradually can be converted into production grade hosting.

We will be running our Docker containers on an Alibaba Cloud Elastic Compute Service (ECS) Ubuntu 16.04 64 bit 4 Core 8 GB RAM Virtual Machine.

Hosting TensorFlow using Docker on Alibaba Cloud

TensorFlow is an open source library for numerical computation, specializing in machine learning applications. In this tutorial, you will learn how to install and run TensorFlow on a single machine, and will train a simple classifier to classify images of flowers.

What Are We Going to Be Building?

In this lab, we will be using transfer learning, which means we are starting with a model that has been already trained on another problem. We will then be retraining it on a similar problem. Deep learning from scratch can take days, but transfer learning can be done in a much short order.

This lab will train the model of lights on and off based on my demo that I released on YouTube. We will use this same model, but retrain it to tell apart a small number of classes based on our own examples.

What you will learn:

  1. How to use Python and TensorFlow to train an image classifier
  2. How to classify images with your trained classifier

What you need:

  1. A basic understanding of Linux commands
  2. Alibaba Cloud account

1. Install Docker on Ubuntu 16.04

The Docker installation package available in the official Ubuntu 16.04 repository may not be the latest version. To get the latest and greatest version, install Docker from the official Docker repository. This section shows you how to do just that.

First, add the GPG key for the official Docker repository to the system:

Add the Docker repository to APT sources:

Next, update the package database with the Docker packages from the newly added repo:

Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo:

You should see output similar to the follow:

Notice that docker-ce is not installed, but the candidate for installation is from the Docker repository for Ubuntu 16.04. The docker-ce version number might be different.

Finally, install Docker:

Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running:

The output should be similar to the following, showing that the service is active and running:


2. Setup TensorFlow Docker Image on Alibaba Cloud

In order to set the environment variables and quick setup of TensorFlow, I have created docker image of TensorFlow and you can pull it fast.

In above Ubuntu image of Alibaba Cloud, after installing Container and docker, execute following steps.

Once you do the following, you will see below output when you run docker images and docker ps –a commands.

Congratulations! You have successfully configured Docker image of TensorFlow on your Alibaba Cloud VM Container.

3. Starting and Entering TensorFlow Container

Once you have completed pulling the image, execute following steps.

First execute mkdir tf_files in / path. Execute below command

You will be now in container prompt of TensorFlow as shown below

4. Training and Testing Your Model

Execute below steps to train your lights model.

Execute cd .. command so that you come out of tf_files folder.

Execute following command cp -a btf_files/. tf_files/

Now enter into tf_files and see list of files.

In above folder, I have already put some of the lights on and off images under lights folder. There is a testimages folder which contains sample image which we will use to test after training the model. Folder tf is the scripts of tensorlfow

Create directory /trained_files by executing mkdir trained_files (Make sure it is in / path)

Execute following command to train your model.

Set variable path as below

Once you set above command, make sure you enter into cd /tf_files/tf and then execute below command.

Once you train the model, test by giving sample image

You should see the following output:

This concludes that image you provided was of light on. You can test multiple images by putting sample in testimages folder. Make sure you execute python scrip by entering into folder tf.


In this tutorial, we have successfully run TensorFlow on Alibaba Cloud using Docker containers for a sample machine learning application.

TensorFlow is an open source software library for numerical computation using data flow graphs. Nodes in the graph represent mathematical operations, while the graph edges represent the multidimensional data arrays (tensors) communicated between them. The flexible architecture allows you to deploy computation to one or more CPUs or GPUs in a desktop, server, or mobile device with a single API.

TensorFlow was originally developed by researchers and engineers working on the Google Brain Team within Google’s Machine Intelligence research organization for the purposes of conducting machine learning and deep neural networks research, but the system is general enough to be applicable in a wide variety of other domains as well.


Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store