Dockerfile for multiple Docker containers

I am working with Docker and I have a web-app that requires the following:

  1. Tomcat
  2. PostgresSQL
  3. MongoDB

To install item 2 and 3 I do the following:

  • The command '/bin/sh -c returned a non-zero code: 127
  • Kubernetes - kubectl exec bash - session drop and line width
  • How to set up Cassandra Docker cluster in Marathon with BRIDGE network?
  • Very slow network performance of Docker containers with host's network
  • JUJU charm and image based build (qcow2)
  • Apache remap to apache within docker container
  • I can run a command for PostgresSQL like :

    docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
    

    For Mongodb I run:

    docker run --name some-mongo -d mongo
    

    For Tomcat, I have a Dockerfile with Tomcat and copying my war to the apps folder. I build the image using Docker and run it.

    My question is whether there is a better way to coordinate this step by step via separate script? Is Docker compose the solution for this?

    thanks

  • Docker-compose Nginx php-fpm file not found
  • Unable to follow sandbox link in Apache Mesos
  • Docker Rails App and postgres
  • Is it possible to isolate docker container in user-defined overlay network from outside internet?
  • Would Docker or Vagrant be help in creating test machine for our enterprise product
  • Get docker IP address from Image name
  • 2 Solutions collect form web for “Dockerfile for multiple Docker containers”

    A Dockerfile is a recipe for building an image, which is a template for starting containers. To describe a system that is made of multiple containers using standardized images, you would use docker-compose, not a new Dockerfile. You would use a Dockerfile to customize a pre-existing docker image, like mysql or node or ubuntu, for some specific use.

    docker-compose allows you to express multiple docker commands as a .yml file in a specific format.

    You can then use docker-compose up to start the set of containers.

    The docker-compose .yml file for your example might start looking somewhat like this

    some-postgres:
        environment:
            POSTGRES_PASSWORD:mysecretpassword
        image: postgres
    
    some-mongo:
        image: mongo
    

    You would add links between the containers with a links: line. These and other details are in the docs.

    Basically docker-compose is just a yaml file implementation of docker run.
    As docker run has arguments passed to it, these exact same arguments are stipulated in docker compose in a yaml format instead of on the command line.
    Docker compose supports multiple containers too.

    Docker compose has a few other nice features such as docker-compose logs , this command gives logs of all containers started by compose.

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