From d07e42266b9df3021361123ddf39e2af4dce1902 Mon Sep 17 00:00:00 2001 From: Volodymyr Zhukov Date: Wed, 31 Jul 2024 16:57:30 +0300 Subject: [PATCH] Add info how to run containers as a service on ubuntu --- README.MD | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/README.MD b/README.MD index 63ea9d6..0cd3e49 100644 --- a/README.MD +++ b/README.MD @@ -110,6 +110,53 @@ or docker-compose down ``` +#### Run docker container as a service on Ubuntu 24 +in this this example code cloned to your home directory +to run service you need container: +``` +cd tinfoil-shop-tutorial +docker compose build +``` + +create file for your service: +``` +sudo vim /etc/systemd/system/tinfoil-shop-tutorial.service +``` + +with following content: +``` +[Unit] +Description=Tinfoil Shop Tutorial Docker container +After=docker.service +Requires=docker.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/bin/bash -c "docker compose -f /home/user/tinfoil-shop-tutorial/docker-compose.yml up --detach" +ExecStop=/bin/bash -c "docker compose -f /home/user/tinfoil-shop-tutorial/docker-compose.yml stop" + +[Install] +WantedBy=multi-user.target +``` +than: +``` +sudo systemctl enable tinfoil-shop-tutorial +``` + +check results: +``` +sudo systemctl status tinfoil-shop-tutorial +sudo systemctl start tinfoil-shop-tutorial +sudo systemctl stop tinfoil-shop-tutorial +``` + +if something goes wrong check docker container logs: +``` +docker ps +docker logs REAL_CONTAINER_ID +``` + ## wasen't so hard no?