I host numerous Docker services on my Raspberry Pi 4, this setup simplifies inter-container communication and enables flexible management. With custom Bash scripts and configurations, I can enable and disable containers on restart and control service states according to my needs. Please feel free to visit my website at mirekng.com to learn more about me and my projects.
You will need linux server and docker
- Clone the repository:
git clone https://github.com/mireknguyen/mirekng-homepage.git
- Navigate to the project directory: cd mirekng-homepage
- Run the automation script to set up Docker services.
./docker-services-up
- To start the Docker services, run:
cd <project-folder> && ./docker-services-up
- To stop the services, run:
cd <project-folder> && ./docker-services-down
- Create a systemd file
touch /etc/systemd/system/self-hosted.service
- Add this (use your installation directory)
[Unit]
Description=%i service with docker compose
PartOf=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=true
WorkingDirectory=/home/user/self-hosted/
ExecStart=/home/user/self-hosted/docker-services-up
ExecStop=/home/user/self-hosted/docker-services-down
[Install]
WantedBy=multi-user.target
sudo docker-compose --env-file="./.env" --project-directory="./docker-services" -f "./docker-services/service.yml" up -d --remove-orphans
sudo docker-compose --env-file="./.env" --project-directory="./docker-services" -f "./docker-services/service.yml" up -d --remove-orphans