Example of developing and deploying a dockerized Node.js app to Elastic Beanstalk

source on Github at pfeilbr/Elastic-Beanstalk-Docker-Node.js-Example

Local Development Workflow

  1. Edit code. e.g. index.js
  2. Build image

    $ docker build --tag="pfeilbr/eb-docker-node-example" .

  3. Run

    $ docker run -p 80:80 -it -rm -name eb-docker-node-example pfeilbr/eb-docker-node-example

  4. Get docker host ip (optional. only if using boot2docker)

    $ boot2docker ip

  5. Open browser to http://<boot2docker ip>

Initial Deployment

  1. Init git repo

    $ git init .

  2. Add files to repo

    $ git add .

  3. Commit changes

    $ git commit -m "init"

  4. Create eb app

    $ eb init # populate details

    Populate all details

  5. Create environment for app

    $ eb create dev-env

    IMPORTANT Must immediately update the ec2 instance with tags so it doesn't get terminated. Enable termination protection on the ec2 instance.

Output

Deploying Updates

  1. Modify code and test via [Local Development Workflow]
  2. Commit changes

    $ git commit -a -m "my updates"

  3. Deploy to eb

    $ eb deploy

NOTE: Takes between 3-5 min to deploy changes

Output

Establish Interactive Bash Shell in Running Docker Container

  1. ssh into ec2 docker host server

    $ eb ssh

  2. Get container name

    $ sudo docker ps # save off name of container

  3. Connect/attach with an interactive bash session

    $ sudo docker exec -i -t <container name> bash

Example Session with Output