Welcome to FreeSoftwareServers Confluence Wiki

A common example which I'll use is that I have a DB GUI that I don't want always running but I want to easily be able to turn on.

See:

https://stackoverflow.com/questions/37254881/is-there-any-way-to-disable-a-service-in-docker-compose-yml

https://stackoverflow.com/a/65957695/5079799

https://docs.docker.com/compose/profiles/

version: "3.9"
services:
  frontend:
    image: frontend
    profiles: ["frontend"]

  phpmyadmin:
    image: phpmyadmin
    depends_on:
      - db
    profiles:
      - debug

  backend:
    image: backend

  db:
    image: mysql
docker-compose --profile debug up
WD=/opt/openproject/setup
cat << EOF >$WD/openproject.service.setup.sh
cat << EOL >/lib/systemd/system/openproject.service
[Unit]
Description=openproject_Docker
Requires=docker.service network-online.target

[Service]

Restart=on-abnormal
ExecStart=/usr/bin/docker-compose --project-name openproject --project-directory $WD -f $WD/docker-compose.yaml up
ExecStop=/usr/bin/docker-compose --project-name openproject --project-directory $WD -f $WD/docker-compose.yaml stop

[Install]
WantedBy=multi-user.target
EOL
systemctl enable openproject
systemctl restart openproject
systemctl status openproject
EOF
chmod +x $WD/openproject.service.setup.sh
$WD/openproject.service.setup.sh

###
WD=/opt/openproject/setup
cat << EOF >$WD/pgadmin.service.setup.sh
cat << EOL >/lib/systemd/system/pgadmin.service
[Unit]
Description=openproject_pgadmin_Docker
Requires=docker.service network-online.target

[Service]

Restart=on-abnormal
ExecStart=/usr/bin/docker-compose --profile debug --project-name openproject --project-directory $WD -f $WD/docker-compose.yaml up
ExecStop=docker stop openproject_pgadmin

[Install]
WantedBy=multi-user.target
EOL
systemctl enable pgadmin
systemctl restart pgadmin
systemctl status pgadmin
EOF
chmod +x $WD/pgadmin.service.setup.sh
$WD/pgadmin.service.setup.sh
  • No labels