- Overview
- Guides
- Getting Cat9K Setup
- Docker Applications Development
- ThousandEyes Application Hosting
- Getting started with Docker Applications Deployment
- Application Hosting Configuration
- Build Docker applications Using Docker Toolchain
- Open Source Application Deployment
- Cisco ASAc Application Deployment
- Third Party Application Deployment
- Learn More
- Developer Resources
- Community and Support
Introduction to Docker
Docker is a well-known containerization platform and is increasingly being adopted by developers and administrators. You can use Docker ecosystem to develop applications. The following list shows some of the advantages to using Docker:
- Most developers are familiar with using Docker tools to create Docker images.
- Docker hub hosts a variety of container images, that helps quick deployments
- The base Docker images are also supported by distro-specific repositories helping developers to easily get libraries, binaries needed for their applications without having to worry about compiling them from sources and resolving dependencies (e.g.
apk add nodejs
) - Docker and its ecosystem tools are well documented.
I have a Docker App
If you already have a working docker App in tar format, follow Getting Started with Docker App Deployment
I need a Docker App
Here are prerequisites and workflow to build your own docker app.
Prerequisites
- Docker >= 1.12 (preferred would be 1.26) installed on your development machine
Docker Workflow
The following diagram shows a high-level workflow for how to create applications using Docker tools and images.
Required Developer Skills
Developers are expected to be familiar with the process of working with Docker and creating docker images.
In addition, they are expected to:
- have an intermediate understanding of Linux including: rootfs, partition, system initialization, and package installation.
- be familiar with how to build a Linux application.
- customize and configure linux systems.
Tutorial: Build Sample Docker Python Simple App
The goals of this tutorial are to demonstrate various development tasks and concepts and to implement a simple Python based Container application using Docker.
Sample Code
This sample application code is maintained here.
Clone this repo and use branch master
. Find the application under the following directory: 'simple-python-app'
Copy$ git clone https://github.com/CiscoIOx/docker-demo-apps.git -b master
$ cd docker-demo-apps/simple-python-app
Some parts of the code may be reproduced in this document to give more context. But, always use the above git repo and branch for the latest code.
Procedure Overview
We will cover the following procedures:
- Implementing a simple Python application
- Creating a docker image with Python application
- Testing your application locally using docker tools
- Deploying and testing on the target platform
We will write a simple Python application that virtually simulates gathering temperature data from the device and saving this information to a file poll-temp.log in /var/log directory.
Note: The application examples are demonstrated for IR800 platforms, but the same procedure will be applicable for all other supported app hosting platforms.
Implementing a simple Python application
Setup project directory
Copy$ mkdir simple-python-app
$ cd simple-python-app
Writing a Python Application
Copy$ vi poll-temperature.py
#!/usr/bin/Python
import time
import os
os.makedirs("/var/volatile/log")
f = open('/var/log/poll-temp.log', 'w')
while (1):
s = "%s %s polling temperature ...\n" % (time.strftime("%d/%m/%Y"), time.strftime("%I:%M:%S"))
f.write(s)
f.flush()
time.sleep(5)
Creating a docker image with python application
Let us create a docker image with the above application in it.
Write a Dockerfile
Below is a Dockerfile that accomplishes these tasks:
Copy$ vi Dockerfile
FROM ubuntu:18.04 as base
RUN apt-get update -yq && apt-get install -yq python
COPY poll-temperature.py /usr/bin/poll-temperature.py
RUN chmod 777 /usr/bin/poll-temperature.py
CMD /usr/bin/poll-temperature.py
Note: Assuming the poll-temperature.py file is in the same directory as the Dockerfile.
Creating a docker image
Now let us build an image from this Dockerfile and tag it with a name (iox-simple-py:1.0
).
Copy$ docker build -t iox-simple-py:1.0 .
Check your built image
Copy# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
iox-simple-py 1.0 fc9150946af4 6 seconds ago 17.84 MB
Testing your application locally using docker tools
Let us run the image locally to make sure it works fine. Since
Copy# docker run -d iox-simple-py:1.0
b5205d87312c4e6f058dcbf6289c3d18299127dd8f211407d581fd07b1092a6d
In order to see your application collecting data we need to exec to the container
Copy/ # cd /var/log
/var/volatile/log # ls -la
drwxr-xr-x 2 root root 4096 Nov 2 00:04 .
drwxr-xr-x 5 root root 4096 Nov 2 00:04 ..
-rw-r--r-- 1 root root 352 Nov 2 00:05 poll-temp.log
/var/volatile/log # tail -F poll-temp.log
02/11/2016 12:04:41 polling temperature ...
02/11/2016 12:04:46 polling temperature ...
02/11/2016 12:04:51 polling temperature ...
02/11/2016 12:04:56 polling temperature ...
02/11/2016 12:05:01 polling temperature ...
02/11/2016 12:05:06 polling temperature ...
02/11/2016 12:05:11 polling temperature ...
02/11/2016 12:05:16 polling temperature ...
02/11/2016 12:05:21 polling temperature ...
Create tar file
Using Docker Save command, create the tar file which can be installed on Catalyst 9000.
Copy$ docker save iox-simple-py:1.0 -o iox-simple-py.tar
To deploy this application on Catalyst 9000, refer to Getting Started with Docker App Deployment.