Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I structure my docker projects for easy deployment?

Right now I have multiple components of my application in the same folder linked together with a docker-compose enter image description here

This works really well in development, but when I want to push to production it's kind of fuzzy. If I keep this structure I cannot use only dockerhub to host my images because the docker-compose which links them will be missing. If I use git to pull down my docker-compose, what would be the point of dockerhub? Why not just clone my whole repo and run docker-compose up each time?

I could alternatively store each component separately in separate github repos, pushing them up to dockerhub when pushed to master. Then, simply combine them from the hub with a dockercompose. This seems less than ideal too, since one would have to clone and push to several different repos to make a change which effects the system.

How do you do it?

like image 943
Dylan Harness Avatar asked Apr 27 '16 22:04

Dylan Harness


People also ask

How do you Dockerize a simple application?

js Application to Production. The easiest way to deploy a Dockerized application on a remote server is to transfer the application's image with docker pull and then use docker run . This runs the application in a container similar to how you'd do it in your development environment.

Is Docker good for small projects?

Your project is relatively small and simpleDocker is really handy if your software consists of multiple parts. It makes it easier to install these and keep a track of all the dependencies.


2 Answers

I have two parts: source code and config files (docker files, docker-compose files...)

I put Dockerfile and docker-compose in a folder with the struct like you and push it to a git repository. For source code (and other data), I have to manage it by hand, with separated git repositories for source code to push and pull each time it needs to update.

Be careful with the production server, just update small part instead of the whole server.

like image 123
Finn Avatar answered Sep 27 '22 19:09

Finn


Check out the new (still experimental) docker-app (June 2018)

It will allow you to push your docker-compose to DockerHub, as well as launch your app (through docker-compose) with settings variations between dev and prod.

See example:

You can create an Application Package based on this Compose file:

$ docker-app init --single-file hello
$ ls
docker-compose.yml
hello.dockerapp

The new new file hello.dockerapp contains three YAML documents:

  • metadatas
  • the Compose file
  • settings for your application

See "Sharing your application on the Hub"

You can push any application to the Hub using docker-app push:

$ docker-app push --namespace myHubUser --tag latest

This command will create an image named myHubUser/hello.dockerapp:latest on your local Docker daemon, and push it to the Hub.

like image 31
VonC Avatar answered Sep 27 '22 20:09

VonC