ruk·si

🐋 Docker
Deployments

Updated at 2015-12-16 00:52

Docker can be used to deploy your code in many ways.

The simplest way is to host the Dockerfile in your code repository and build as you deploy. AWS Elastic Beanstalk works similar to this.

  1. Add Dockerfile and your code to a git repository.
    1. For example, Dockerfile with FROM Ruby on Rails + your Ruby on Rails.
    2. Dockerfile contains all steps of deployment like bundle exec.
  2. Your staging and production servers have git where you can push.
  3. Pushing to the server will trigger deployment.
  4. docker build -t ruksi/my-image:pre-COMMIT_SHA . using the Dockerfile
  5. docker run ... with alternative port to run tests.
  6. docker commit -c "EXPOSE 8080" ... to change the port after tests.
  7. Remove the previous container.
  8. docker run ... using the Docker image created by the previous step.

Another common way is to have a build server and deploy a prebuilt image. This provides really fast deployments that are nice if up and downscaling services is common e.g. with Elastic Container Service.

  1. Add Dockerfile and your code to a git repository.
  2. You have separate code repository or branch in GitHub that provides webhooks for deployments.
  3. When production repository or branch receives a push, it will trigger a build phase on your build server.
  4. docker build -t ruksi/my-image:COMMIT_SHA .
  5. docker run -d --name my-container ruksi/my-image:COMMIT_SHA
  6. Run tests.
  7. docker push ruksi/my-image:COMMIT_SHA
  8. Somehow pull and run on the running servers; webhooks, AWS SNS, Lambda.

It's a good practice to have one Dockerfile per project.