[This article was written by Mark van Holsteijn.]
Docker reached production status a few months ago. But having the container technology alone is not enough. You need a complete platform infrastructure before you can deploy your docker application in production. Amazon AWS offers exactly that: a production quality platform that offers capacity provisioning, load balancing, scaling, and application health monitoring for Docker applications.
In this blog, you will learn how to deploy a Docker application to production in five easy steps.
For demonstration purposes, you are going to use the node.js application that was build for CloudFoundry and used to demonstrate Deis in a previous post. A truly useful app of which the sources are available on github.
1. Create a Dockerfile
# DOCKER-VERSION 1.0 FROM ubuntu:latest # # Install nodejs npm # RUN apt-get update RUN apt-get install -y nodejs npm # # add application sources # COPY . /app RUN cd /app; npm install # # Expose the default port # EXPOSE 5000 # # Start command # CMD ["nodejs", "/app/web.js"]
2. Test your docker application
Now you can create the Docker image and test it.
$ docker build -t sample-nodejs-cf . $ docker run -d -p 5000:5000 sample-nodejs-cf
Point your browser at http://localhost:5000, click the 'start' button and Presto!
3. Zip the sources
Now you know that the instance works, you zip the source files. The image will be build on Amazon AWS based on your Dockerfile.
$ zip -r /tmp/sample-nodejs-cf-srcs.zip .
4. Deploy Docker application to Amazon AWS
Now you install and configure the amazon AWS command line interface (CLI) and deploy the docker source files to elastic beanstalk. You can do this all manually, but here you use the script deploy-to-aws.sh that I created.
$ deploy-to-aws.sh \ sample-nodejs-cf \ /tmp/sample-nodejs-cf-srcs.zip \ demo-env
After about 8-10 minutes your application is running. The output should look like this.
INFO: creating application sample-nodejs-cf INFO: Creating environment demo-env for sample-nodejs-cf INFO: Uploading sample-nodejs-cf-srcs.zip for sample-nodejs-cf, version 1412948762. upload: ./sample-nodejs-cf-srcs.zip to s3://elasticbeanstalk-us-east-1-233211978703/1412948762-sample-nodejs-cf-srcs.zip INFO: Creating version 1412948762 of application sample-nodejs-cf INFO: demo-env in status Launching, waiting to get to Ready.. ... INFO: demo-env in status Launching, waiting to get to Ready.. INFO: Updating environment demo-env with version 1412948762 of sample-nodejs-cf INFO: demo-env in status Updating, waiting to get to Ready.. ... INFO: demo-env in status Updating, waiting to get to Ready.. INFO: Version 1412948762 of sample-nodejs-cf deployed in environment INFO: current status is Ready, goto http://demo-env-vm2tqi3qk4.elasticbeanstalk.com
5. Test your Docker application on the internet!
Your application is now available on the Internet. Browse to the designated URL and click on start. When you increase the number of instances at Amazon, they will appear in the application. When you deploy a new version of the application, you can observe how new versions of the application appear without any errors on the client application.