🐋 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.
- Add Dockerfile and your code to a git repository.
- For example, Dockerfile with
FROM
Ruby on Rails + your Ruby on Rails. - Dockerfile contains all steps of deployment like
bundle exec
.
- For example, Dockerfile with
- Your staging and production servers have git where you can push.
- Pushing to the server will trigger deployment.
docker build -t ruksi/my-image:pre-COMMIT_SHA .
using the Dockerfiledocker run ...
with alternative port to run tests.docker commit -c "EXPOSE 8080" ...
to change the port after tests.- Remove the previous container.
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.
- Add Dockerfile and your code to a git repository.
- You have separate code repository or branch in GitHub that provides webhooks for deployments.
- When production repository or branch receives a push, it will trigger a build phase on your build server.
docker build -t ruksi/my-image:COMMIT_SHA .
docker run -d --name my-container ruksi/my-image:COMMIT_SHA
- Run tests.
docker push ruksi/my-image:COMMIT_SHA
- Somehow
pull
andrun
on the running servers; webhooks, AWS SNS, Lambda.
It's a good practice to have one Dockerfile per project.