4
votes

My current setup:

  • When changed code pushed to Github, Travis trigger build.
  • Travis build the container using the Dockerfile and push to dockerhub.

What I need to achieve:

  • Pull the container from docker hub inside production environment.
  • Run the container exposing required ports.

Approaches:

  • SSH into production environment and pull the container and run (using travis.yml).

I want to pull and run the container in production right after the Travis build is succeeded. SSH seems hacking and I need the best practice to achieve this.

1
What is your prod environment? is it a some kind of cloud environments or physical servers?Yaron Idan
Amazon EC2 linux instancesith
Is using a managed docker solution an option? We're using elastic beanstalk and the CI pipeline works great. It's a bit of extra work but it will make your deployments a lot smoother.Yaron Idan
i look into that later. need a soft solution for the time being.sith
Then your 2 other options are using travis to run a bash file on the server, which is a bit hacky, as you mentioned - and might present problems if you try to add instances to your app and perform rolling updates and blue/green deploys (ECS and beanstalk will give you that out of the box). The other solution is using a tool for that - like AWS codedeploy or a CM tool, but that will probably take more time than launching a beanstalk app.Yaron Idan

1 Answers

1
votes

You have a few options there :

1 - You actually want to pull the image after the DockerHub build is done, not after travis is done, in that case you can use DockerHub webhooks to call some kind of service (it can boil down to any kind of script) on your server, which will pull the image and run it.

From https://docs.docker.com/docker-hub/repos/#/webhooks :

You can use a Hub repository webhook to notify people, services, and other applications after a new image is pushed to your repository (this also happens for Automated builds). For example, you can trigger an automated test or deployment to happen as soon as the image is available.

2 - Use something like Ansible to avoid SSH'ing into the machine yourself. You write an Ansible role once, and it will run in your Travis build. There is a very good docker module for Ansible so you'll be good.

3 - Use a more adapted infrastructure like Amzon ECS, which is basically one or a group of EC2 instances that run and manage Docker containers and images for you. If you know how to spin an EC2 instance, making a simple ECS instance will not be a problem at all.

I hope this helps.