Using Compose file in Docker

You can use the docker-compose.yml file for defining volumes and services.

About this task

The default path for a Compose file is ./docker-compose.yml. Below is an example of launching the postgres container.

Procedure

  1. Open the docker-compose.yml.
  2. Launch container postgres with 10 GB Flocker volume mounted in the /data path of the container by setting the required parameters in the file:
                       
    version: "2"
     
    volumes:
       volumename1:
          driver: "flocker"
          driver_opts:
            size: "10GiB"
            profile: "gold"
     
    services:
       postgres :
         image: postgres 
         environment:
            - "PGDATA=/var/lib/postgresql/data"
         volumes:
            - 'postgres_vol5:/var/lib/postgresql/data'
  3. Run the docker-compose up command. The command reads the docker-compose.yml file in the current directory and launches the container with the new volume.