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?

  • Kubernetes delete secret docker-registry error Unable to connect to the server: x509
  • Go & Docker: I'm able to run a go web server when using stdlib, when I use custom packages errors occur
  • Allow routing to docker 172.17.0.0/16 network without NAT?
  • Creating a docker-compose with PHP drivers for mongo+memcache+ES
  • Can't pull the splash image from docker
  • Modern status of private Docker registries/repos
  • What are differences between Docker and Octopus Deploy
  • Host Global Python Object in Docker Container
  • How to know if a docker container is running in privileged mode
  • Do you have any resource explaining how to use Firebase Test lab with GitLab pipeline?
  • Testing Mongo with Docker
  • Docker exec command not using the mounted directory for /
  • One Solution collect form web for “Best practice using Dockerfile with docker-compose and vcs”

    You can use a structure like this:

    project/
     - 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:

     frontend:  
      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 wait-for-it.sh 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.