ruk·si

🐋 Docker
Deployments

Updated at 2015-12-16 00:52

Docker is a tool that can be used numerous ways to deploy your code.

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

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