Facebook
From Blush Plover, 2 Years ago, written in Plain Text.
This paste is a reply to Re: dockercompose from Round Matamata - go back
Embed
Viewing differences between Re: dockercompose and Re: Re: dockercompose
In docker-compose.yml: (Infrastructure Code)
----------------------------------------------
version: '3'

services:
  dbos:
    image: mysql:5.7
    volumes: (This Will Mount the Volume)
          - mysql_storage_new:/var/lib/mysql
    restart: always
    envirnoment:
          MYSQL_USER: vimal
          MYSQL_ROOT_PASSWORD: rootpass
          MYSQL_PASSWORD: redhat
          MYSQL_DATABASE: mydb

  wpos:
    image: wordpress:5.1.1-php7.3-apache
    volumes: (This Will Mount the Volume)
              - wp_storage_new:/var/www/html
    restart: always
    depends_on:
                - dbos
    ports:
              - 8081:80
    environment:
            WORDPRESS_DB_HOST: dbos
              WORDPRESS_DB_USER: vimal
              WORDPRESS_DB_PASSWORD: redhat
              WORDPRESS_DB_NAME: mydb

volumes: (This Will Create the Volumes)
  wp_storage_new:
  mysql_storage_new:
----------------------------------------------
Here, 
version: '3' mean we need to specify which docker-compose version we are using.
services: is used to launch the containers.
dbos is the name of the container.
image key has single value mysql:5.7
volumes key is kind of list in here so we use hyphen "-" . There will be no space after ":" in mysql_storage_new:/var/lib/mysql , Here "volumes' is used to mount the location.
restart key has the value always which mean this container will always start in background when we run docker-compose.
environment key has block of Statements so we use Indent here.
depends_on key creates the link with wpos to dbos.
ports key do the PAT to 8081 to 80. or we can say expose the 80 port to outside world using 8081 port no.
volumes key is used to create the storage so that services can mount the storage locations.