Best practice using Dockerfile with docker-compose and vcs

I have a question regarding best practice.

Lets say I have a webfrontend developed in angularjs and a api to get data from. I put those two in separate repositories.
Now I want to dockerize the whole thing. My idea was to put a Dockerfile in each project which specifies their environment. Until now its fine but what when I also have a docker-compose file which starts those two services simultanously? First of in which repo should I put this file and secondly how can I assure, that the images are always uptodate?

  • Register an instance to an AWS ECS cluster
  • MySQL 5.5.44 “native” 32% faster than dockerized MySQL 5.5.44
  • docker-compose up is starting the container and immediately stopping them
  • How to set environment variables via env-file
  • How do I run Apache 2 on Alpine in Docker?
  • Docker container granularity: SOA or monoliths?
  • Docker-machine : ca.pem not found
  • Deploy a docker app using volume create
  • How to properly share a folder between few docker containers in read mode?
  • Docker container not connecting to https endpoints
  • How to uninstall docker-engine?
  • Docker swarm over IPv6
  • One Solution collect form web for “Best practice using Dockerfile with docker-compose and vcs”

    You can use a structure like this:

     - project/docker-compose.yaml
     - project/frontend/ (contains Dockerfile + necessary files)
     - project/api/ (contains Dockerfile + necessary files)

    In your docker-compose.yaml you can write something like this for each image:

      build: ./frontend #folder in which Dockerfile of frontend is saved (to build the image)
      image: my-frontend:1.0 #give a name to your image
    container_name: frontend-container #containername when a container instance of your image is running

    To start docker-compose you can run docker-compose up --build. The --build tag will recreate your images when there are changes so you can keep your compose up to date when there are changes in the dockerfile (image).

    Docker-compose is ‘reading’ from up to bottom. So the service you describe first in your docker-compose.yaml will be created first. I would think it’s your API because that can probably exist on its own and your frontend needs to connect with it. Sometimes your first service is started too slow, which means the second service is already up but can not find the first service (to connect with) and it crashes. This can be solved by using a script. Your second service will use the script and check when the first service is up. When it’s up, it will start its own service.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.