Home > OS >  Comment out docker-compose block with bash script
Comment out docker-compose block with bash script

Time:10-11

I am making a project for local development with dockerized apps. I have 3 different domain on my company that each domain has one docker-compose file with 5 services. (15 projects)

If User of my project wants to deploy only 1 service of their domain or/and 2 of the other domains projects, I have to comment out services in other docker-compose files that dont want to be deployed.

So my question is How can i comment out docker-compose(Go) files block with bash script? I want to choose the lines with their context. For example in below example i want to comment out ap2-php-fpm section. I cant make a work around solution because more projects incoming. I have to intervene go language script with bash script.

Demonstration

version: '3.3'

services:
  app-php-fpm:
    container_name: app
    build:
      context: ${src}/
    volumes:
        - $path:path
    networks:
      general-nt:
        aliases:
        - app
    expose:
        - "9000"

  ap2-php-fpm:
    container_name: app
    build:
      context: ${src}/
    volumes:
        - $path:path
    networks:
      general-nt:
        aliases:
        - app
    expose:
        - "9000"

networks:
  general-nt:
    external: true

I want to make this file as below with bash script.

version: '3.3'

services:
  app-php-fpm:
    container_name: app
    build:
      context: ${src}/
    volumes:
        - $path:path
    networks:
      general-nt:
        aliases:
        - app
    expose:
        - "9000"

  # ap2-php-fpm:
  #   container_name: app
  #   build:
  #     context: ${src}/
  #   volumes:
  #       - $path:path
  #   networks:
  #     general-nt:
  #       aliases:
  #       - app
  #   expose:
  #       - "9000"

networks:
  general-nt:
    external: true

CodePudding user response:

For many practical purposes, it may be enough to run docker-compose up with specific service names. If you run

docker-compose up -d app-php-fpm

it will start the service(s) on the command line, and anything it depends_on:, but not anything else. That would avoid the need to comment out parts of the YAML file. You could otherwise interact with the containers normally.

  • Related