Skip to content

Docker Compose

Gary Moore edited this page Jan 10, 2024 · 3 revisions

Run docker compose on VM startup

Create a Systemd Service Unit:

To make Docker Compose start on boot, you can create a Systemd service unit. Create a file, for example, /etc/systemd/system/docker-compose.service, and add the following content:

[Unit]
Description=Docker Compose Service
Requires=docker.service
After=docker.service

[Service]
Restart=always
WorkingDirectory=/path/to/your
ExecStart=/usr/bin/docker-compose up -d

[Install]
WantedBy=multi-user.target

To create the file using nano:

sudo nano /etc/systemd/system/docker-compose.service

Set Permissions:

Make sure the file has the correct permissions:

sudo chmod 644 /etc/systemd/system/docker-compose.service

Enable and Start the Service:

Enable the service to start on boot and start it for the current session:

sudo systemctl enable docker-compose
sudo systemctl start docker-compose

Verify the status to ensure there are no errors:

sudo systemctl status docker-compose

If there are any issues, check the logs:

sudo journalctl -xe