A Docker container is a platform to build, ship and run applications. Further information here. Using the Docker system enables to run test applications on your local Linux machine and make them ready for deployment in one external server machine or in a cloud server. In general, an application requires several sub-applications and dependencies in order to run properly. In order to manage and control this work-flow and to automate processes, Ansible is used. The advantages of a joint use of Ansible and Docker are described in this blog.
In the framework of Emodnet Chemistry 2, one of the final stages is to deploy the developed applications on the cloud at Cineca servers. It is a good practice to run test applications on the same OS as the external server. We ran our test on a Debian wheezy OS (Debian 7.8), as the cloud server runs on a Debian wheezy machine as well.
Before shipping the application to a server, it needs to be prepared ad-hoc. The installation of some packages is required.
Install git version control system and create a
src folder in your home directory. Inside
clone the openearth/stack repository and
emodnet" branch within the
Create a virtual environment using
virtualenvwrapper . Check if you have it already with
apt-cache search virtualenvwrapper. If not, install it. Create a virtual environment called
workon ansible to work on
ansible virtual environment and pip install it.
You might need to install Ansible from source and get some additional packages from debian distribution package manager:
Ansible installation might require the installation of additional packages as:
Still from ansible virtual environment, run the
playbook.yml with the following command:
As defined in the playbook, Docker will be installed and a Docker container will be created.
The cloud server needs to have access to our Docker applications. As we need to run web services in docker containers, it can be useful to run a reverse proxy in front of the containers to simplify deployment, because of the hassles related to the addressing of a Docker container from the host. Usually containers are started and stopped in the server. A useful utility that takes into account these events is docker-gen.
A way to do that is to let the Virtual host act as reverse proxy. A number of operations need to be done by the server managers, who would need to know:
- which services need to be deployed
- which ports need to be open
- what is the proxy configuration
- the list of Docker commands as
sudo docker run <flags> <container name>
ansible tasks for the deployment of the docker container for Emodnet Chemistry 2 are here. However, sometimes just a few little changes to the services are needed. In that case, here you find summarized 8 steps to tackle in order to have a successful interaction with a docker container. The examples below are based on Emodnet Chemistry 2 and the server in use is ogs02.cineca.it, though the instructions below are valid in general.
- Work on local or Project folder:
svn Commitfunctions in OpenEarthTools (...\python\applications\wps\processes\ and ...\python\OpenEarthTools\openearthtools\io\pyodv\ ) OR/AND in the project folder (...\1207195\B. Measurements and calculations\wps_processes\ and \1207195\B. Measurements and calculations\docker\ ).
- Access the server via WinSCP:
Copy the changes from local (or Project folder) to /home/deltares02/docker_images/ in the cloud server (ogs02.cineca.it).
Access the server via Putty:
Check the running containers and the docker images available.
Execute commands in the docker machine:
During the previous
docker runcommand the VOLUME (shared filesystems) option was triggered: "
-v /home/deltares02/docker_images:/mnt" (see http://docs.docker.com/reference/run/ )
Therefore we are now able to access the main machine via the docker container, and copy files from the mounted folder to the directory where the processes run. Then exit:
Commit the docker container by saving the image:
Check again what docker containers are running by typing
docker psand the saved images by typing
docker images. Then commit the changes. A long file name is returned as output:
After that we can check if our new image is there:
Stop the former docker container and run the newly created image:
docker psagain will give an empty list of running containers. Let's
docker runthe newly created image:
Test the processes on the Web server via the brower. For instance:
If the result is good, you can exit Putty window. If you open Putty again and access ogs02.cineca.it, you will get the new running container:
Save the image (and load it in a new machine):
Saving the Docker image is not always necessary but it's good practice. Saving the Docker image allows the loading and deployment on another machine.
Save the image as a tarball, zip the image, and copy it on a new machine:
The Docker image can now be copied to a new machine, loaded by unzipping the file, then "docker load" the image, find it and tag it: