After testing Docker on a couple of configurations (laptop/server/Raspberry Pi) on earth it was time to go in the air and use the cloud. As Docker runs on a number of Unix distributions it should be easy to use Docker in the cloud as a lot of cloud vendors offer compatible distributions. Some of the vendors that are able to run Docker in the cloud are DigitalOcean, Rackspace and Amazon EC2. As I’m a Dutch guy I wanted the cheapest option and luckily Amazon offers a free option.
Register for Amazon AWS and create an instance following the instructions on the Docker site. For this test I used an ‘Ubuntu Server 13.10 (PV)’. This is the same Ubuntu version as I used for previous blogs and it’s one of the free instances.
Configure the correct security groups in Amazon EC2. Configure SSH to connect to the instance and HTTP to connect to Tomcat.
Connecting with SSH
Download the pem file and use it to connect to your instance. The command should be like this:
ssh -i <filename>.pem ubuntu@ec2-XXXXXXXX.us-west-2.compute.amazonaws.com
Be careful, the username is ‘ubuntu‘ and not the ‘ec2-user‘ which was mentioned in the documentation.
Simply use the same commands as mentioned in the previous blog.
sudo apt-get update sudo apt-get install linux-image-extra-`uname -r` sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 sudo sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list" sudo apt-get update sudo apt-get install lxc-docker sudo docker run -i -t ubuntu /bin/bash
Creating a Docker container
Create a ‘Dockerfile’ for instance with ‘nano’ with the following content:
FROM ubuntu:saucy # Update Ubuntu RUN apt-get update && apt-get -y upgrade # Add oracle java 7 repository RUN apt-get -y install software-properties-common RUN add-apt-repository ppa:webupd8team/java RUN apt-get -y update # Accept the Oracle Java license RUN echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 boolean true" | debconf-set-selections # Install Oracle Java RUN apt-get -y install oracle-java7-installer # Install tomcat RUN apt-get -y install tomcat7 RUN echo "JAVA_HOME=/usr/lib/jvm/java-7-oracle" >> /etc/default/tomcat7 EXPOSE 8080 # Download Slashdot homepage RUN mkdir /var/lib/tomcat7/webapps/slashdot RUN wget http://www.slashdot.org -P /var/lib/tomcat7/webapps/Slashdot RUN wget http://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war -P /var/lib/tomcat7/webapps # Start Tomcat, after starting Tomcat the container will stop. So use a 'trick' to keep it running. CMD service tomcat7 start && tail -f /var/lib/tomcat7/logs/catalina.out
Build the container using the following command:
sudo docker build -t tomcat7 .
Start the Docker container
Start the container using the following command:
sudo docker run -p 80:8080 -d tomcat7
Test the Docker container
Try the following URL’s in your browser:
Docker is working perfectly in the cloud. This blog and my previous blogs show that Docker can run on various configurations. Not only on standard laptops or servers, but also on ARM (Raspberry Pi) and in the cloud. Using Docker containers to run your applications gives companies a lot of flexibility. It is possible to quickly deploy the applications on another platform. Moving applications across platforms enables companies to use resources more effectively and even gives them the possibility to run the applications on the ‘cheapest platform of the day’.