Docker rails and git app

Suppose I have a container that is fully equipped to serve a Rails application using Passenger and Apache, and I have a host that goes to / var / www / app / public in my container. Since the container should look like a process, what would I do when the Rails code changes? If the app been cloned using Git and changes are expected in the repo, how can the container pull in these changes automatically?

+4
docker
Sep 14 '13 at 20:36
source share
3 answers

You have the choice of how you want to structure your container, depending on your deployment philosophy:

  • Minimum:. You set all rail prerequisites in the Docker file (RUN commands), but ENTRYPOINT can be something like " git pull && bundle install --deployment && rails run ". When loading the container, it will receive your last code.

  • Snapshot: Same as above, but ENTRYPOINT is also a RUN command. Thus, the container has a pre-installed snapshot of the code, but it will be updated when the container is loaded. Sometimes this can speed up loading time (i.e. if most of the gemstones are already installed).

  • Container as Deployment: Same as above, but change the ENTRYPOINT value to " rails run ". So your container is your code. You will have to create new containers every time you change rails (automation!). The advantage is that your container will not need to bind to your code repo at all. The disadvantage is that you must always remember what the last container is. (Tags can help) And right now, Docker does not have a good history of cleaning old containers.

+8
Sep 15 '13 at 19:00
source share

In this case, it seems that you created image and now run this image in container .

Using the image that your running container starts with, you can add another build step to git to pull out the latest code. I would consider this incremental update as your building on an already existing image. I would recommend tagging and clicking on your (assuming you use a private index) appropriately. A new image will be available for launch.

Depending on the need, you can also restore the base image of your software. I assume that you are using a Dockerfile to create a source image that includes a git check of your software. You can then tag and click on your index to use accordingly.

0
Sep 15 '13 at 11:07
source share

In docker v0.8, you can run a new command in a running container so that you can do what you want.

In the meantime, one solution would be to use volumes.

Option 1: Managed Volume Dockers

  FROM ubuntu ... VOLUME [ "/var/www/app/public" ] ADD host/src/path/var/www/app/public   CMD > 

Run and run your container, then when you need git pull, you can simply:

  $docker ps # - >     $ docker run -volumes-from < container id > <    git  > sh -c 'cd/var/www/app/public && & & git pull -u ' > 

This will cause your first running container to update sources.

Option 2: Host Volumes

You can start your container with

  $docker run -v `pwd`/srcs:/var/www/app/public <yourimage> > 

and then just git pull in the source directory of your host, it will update the container sources.

0
Sep 17 '13 at 21:33
source share



All Articles