Blog

How to deploy a Docker application into production on Amazon AWS

17 Oct, 2014

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

First thing you need to do is to create a Dockerfile to create an image. This is quite simple: you install the node.js and npm packages, copy the source files and install the javascript modules.

# 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.
[code language=”bash”]
$ docker build -t sample-nodejs-cf .
$ docker run -d -p 5000:5000 sample-nodejs-cf
[/code]
Point your browser at https://xebia.com/blog: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.
[code language=”bash”]
$ zip -r /tmp/sample-nodejs-cf-srcs.zip .
[/code]

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.
[code language=”bash”]
$ deploy-to-aws.sh \
sample-nodejs-cf \
/tmp/sample-nodejs-cf-srcs.zip \
demo-env
[/code]
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.
For more information, goto Amazon Elastic Beanstalk adds Docker support. and Dockerizing a Node.js Web App.

guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Vitalie Brinza
Vitalie Brinza
7 years ago

Hello Mark,
thanks for useful article.
I have an issue which i try to fix. Hope you can help.
When i try deploy first time i get this output https://gist.github.com/anonymous/ddb24b6b4dbd9ff7933e
In your script i’ve changed:
1. SOLUTION_STACK=${4:-64bit Amazon Linux 2014.09 v1.0.10 running Docker 1.3.2}
2. VERSION=$(stat -f “$FILE”)

Craig
Craig
7 years ago

Good post. But going to http://localhost:5000/ shows “This webpage is not available” for me. I’m on a mac, not sure if that’s related.
Also, you left out Step 0:
$ git clone git@github.com:mvanholsteijn/sample_nodejs_cf.git
You alluded to it, but didn’t explicitly say to check it out and create the Dockerfile in the same dir as it.

Explore related posts