Skip to content

Instantly share code, notes, and snippets.

@a3linux
Forked from mosquito/README.md
Created August 2, 2022 13:16
Show Gist options
  • Save a3linux/aab791911d8e270c829f2378fb4b0dee to your computer and use it in GitHub Desktop.
Save a3linux/aab791911d8e270c829f2378fb4b0dee to your computer and use it in GitHub Desktop.

Revisions

  1. @mosquito mosquito revised this gist May 1, 2022. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -6,9 +6,8 @@ Create file `/etc/systemd/system/[email protected]`. SystemD calling binar
    ```ini
    [Unit]
    Description=%i service with docker compose
    Requires=docker.service
    After=docker.service
    PartOf=docker.service
    After=docker.service

    [Service]
    Type=oneshot
  2. @mosquito mosquito revised this gist May 1, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,7 @@ Create file `/etc/systemd/system/[email protected]`. SystemD calling binar
    Description=%i service with docker compose
    Requires=docker.service
    After=docker.service
    PartOf=docker.service

    [Service]
    Type=oneshot
  3. @mosquito mosquito revised this gist Aug 14, 2021. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -75,4 +75,6 @@ Just add the following line to the `/etc/docker/daemon.json`:
    "log-driver": "journald",
    ...
    }
    ```
    ```

    And restart your docker service.
  4. @mosquito mosquito revised this gist Aug 14, 2021. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -62,4 +62,17 @@ ExecStart=/usr/bin/docker system prune -af
    WantedBy=multi-user.target
    ```

    run `systemctl enable docker-cleanup.timer` for enabling the timer
    run `systemctl enable docker-cleanup.timer` for enabling the timer

    JournalD support
    ================

    Just add the following line to the `/etc/docker/daemon.json`:

    ```json
    {
    ...
    "log-driver": "journald",
    ...
    }
    ```
  5. @mosquito mosquito revised this gist Apr 30, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,9 @@ Create file `/etc/systemd/system/[email protected]`. SystemD calling binar

    ```ini
    [Unit]
    Description=%i service with docker compose Requires=docker.service After=docker.service
    Description=%i service with docker compose
    Requires=docker.service
    After=docker.service

    [Service]
    Type=oneshot
  6. @mosquito mosquito revised this gist Apr 29, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    Docker compose as a systemd unit
    ================================

    Create file `/etc/systemd/system/[email protected]`
    Create file `/etc/systemd/system/[email protected]`. SystemD calling binaries using an absolute path. In my case is prefixed by `/usr/local/bin`, you should use paths specific for your environment.

    ```ini
    [Unit]
  7. @mosquito mosquito revised this gist Apr 29, 2020. 1 changed file with 6 additions and 19 deletions.
    25 changes: 6 additions & 19 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -5,27 +5,14 @@ Create file `/etc/systemd/system/[email protected]`

    ```ini
    [Unit]
    Description=%i service with docker compose
    Requires=docker.service
    After=docker.service
    Description=%i service with docker compose Requires=docker.service After=docker.service

    [Service]
    Restart=always

    Type=oneshot
    RemainAfterExit=true
    WorkingDirectory=/etc/docker/compose/%i

    # Remove old containers, images and volumes
    ExecStartPre=/usr/local/bin/docker-compose down -v
    ExecStartPre=/usr/local/bin/docker-compose rm -fv
    ExecStartPre=-/bin/bash -c 'docker volume ls -qf "name=%i_" | xargs docker volume rm'
    ExecStartPre=-/bin/bash -c 'docker network ls -qf "name=%i_" | xargs docker network rm'
    ExecStartPre=-/bin/bash -c 'docker ps -aqf "name=%i_*" | xargs docker rm'

    # Compose up
    ExecStart=/usr/bin/docker-compose up

    # Compose down, remove containers and volumes
    ExecStop=/usr/bin/docker-compose down -v
    ExecStart=/usr/local/bin/docker-compose up -d --remove-orphans
    ExecStop=/usr/local/bin/docker-compose down

    [Install]
    WantedBy=multi-user.target
    @@ -67,7 +54,7 @@ Type=oneshot
    WorkingDirectory=/tmp
    User=root
    Group=root
    ExecStart=/usr/bin/docker system prune -f
    ExecStart=/usr/bin/docker system prune -af

    [Install]
    WantedBy=multi-user.target
  8. @mosquito mosquito revised this gist Nov 29, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -15,8 +15,8 @@ Restart=always
    WorkingDirectory=/etc/docker/compose/%i

    # Remove old containers, images and volumes
    ExecStartPre=/usr/bin/docker-compose down -v
    ExecStartPre=/usr/bin/docker-compose rm -fv
    ExecStartPre=/usr/local/bin/docker-compose down -v
    ExecStartPre=/usr/local/bin/docker-compose rm -fv
    ExecStartPre=-/bin/bash -c 'docker volume ls -qf "name=%i_" | xargs docker volume rm'
    ExecStartPre=-/bin/bash -c 'docker network ls -qf "name=%i_" | xargs docker network rm'
    ExecStartPre=-/bin/bash -c 'docker ps -aqf "name=%i_*" | xargs docker rm'
  9. @mosquito mosquito revised this gist Nov 29, 2017. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -67,9 +67,7 @@ Type=oneshot
    WorkingDirectory=/tmp
    User=root
    Group=root
    ExecStartPre=-/bin/bash -c 'docker ps -aqf status=exited | xargs docker rm -v'
    ExecStartPre=-/bin/bash -c 'docker images -qf dangling=true | xargs docker rmi -f'
    ExecStart=/bin/docker ps -af status=exited
    ExecStart=/usr/bin/docker system prune -f

    [Install]
    WantedBy=multi-user.target
  10. @mosquito mosquito revised this gist May 19, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -73,4 +73,6 @@ ExecStart=/bin/docker ps -af status=exited

    [Install]
    WantedBy=multi-user.target
    ```
    ```

    run `systemctl enable docker-cleanup.timer` for enabling the timer
  11. @mosquito mosquito revised this gist May 19, 2017. 1 changed file with 37 additions and 0 deletions.
    37 changes: 37 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -37,3 +37,40 @@ Place your `docker-compose.yml` into `/etc/docker/compose/myservice` and call
    systemctl start docker-compose@myservice
    ```


    Docker cleanup timer with system
    ================================

    Create `/etc/systemd/system/docker-cleanup.timer` with this content:

    ```ini
    [Unit]
    Description=Docker cleanup timer

    [Timer]
    OnUnitInactiveSec=12h

    [Install]
    WantedBy=timers.target
    ```

    And service file `/etc/systemd/system/docker-cleanup.service`:

    ```ini
    [Unit]
    Description=Docker cleanup
    Requires=docker.service
    After=docker.service

    [Service]
    Type=oneshot
    WorkingDirectory=/tmp
    User=root
    Group=root
    ExecStartPre=-/bin/bash -c 'docker ps -aqf status=exited | xargs docker rm -v'
    ExecStartPre=-/bin/bash -c 'docker images -qf dangling=true | xargs docker rmi -f'
    ExecStart=/bin/docker ps -af status=exited

    [Install]
    WantedBy=multi-user.target
    ```
  12. @mosquito mosquito revised this gist May 19, 2017. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    Docker compose as a systemd unit
    ================================

    Create file `/etc/systemd/system/[email protected]`

    ```ini
    @@ -28,8 +31,9 @@ ExecStop=/usr/bin/docker-compose down -v
    WantedBy=multi-user.target
    ```

    Place you `docker-compose.yml` into `/etc/docker/compose/myservice` and call
    Place your `docker-compose.yml` into `/etc/docker/compose/myservice` and call

    ```
    systemctl start docker-compose@myservice
    ```
    ```

  13. @mosquito mosquito revised this gist May 19, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    Create file `/etc/systemd/system/[email protected]`

    ```
    ```ini
    [Unit]
    Description=%i service with docker compose
    Requires=docker.service
  14. @mosquito mosquito revised this gist May 19, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Create file `[email protected]`
    Create file `/etc/systemd/system/[email protected]`

    ```
    [Unit]
  15. @mosquito mosquito revised this gist May 19, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    Create file `[email protected]`

    ```
    [Unit]
    Description=%i service with docker compose
  16. @mosquito mosquito revised this gist May 19, 2017. No changes.
  17. @mosquito mosquito revised this gist May 19, 2017. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -26,9 +26,7 @@ ExecStop=/usr/bin/docker-compose down -v
    WantedBy=multi-user.target
    ```

    Place you `docker-compose.yml` into `/etc/docker/compose/myservice`

    and call
    Place you `docker-compose.yml` into `/etc/docker/compose/myservice` and call

    ```
    systemctl start docker-compose@myservice
  18. @mosquito mosquito created this gist May 19, 2017.
    35 changes: 35 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    ```
    [Unit]
    Description=%i service with docker compose
    Requires=docker.service
    After=docker.service
    [Service]
    Restart=always
    WorkingDirectory=/etc/docker/compose/%i
    # Remove old containers, images and volumes
    ExecStartPre=/usr/bin/docker-compose down -v
    ExecStartPre=/usr/bin/docker-compose rm -fv
    ExecStartPre=-/bin/bash -c 'docker volume ls -qf "name=%i_" | xargs docker volume rm'
    ExecStartPre=-/bin/bash -c 'docker network ls -qf "name=%i_" | xargs docker network rm'
    ExecStartPre=-/bin/bash -c 'docker ps -aqf "name=%i_*" | xargs docker rm'
    # Compose up
    ExecStart=/usr/bin/docker-compose up
    # Compose down, remove containers and volumes
    ExecStop=/usr/bin/docker-compose down -v
    [Install]
    WantedBy=multi-user.target
    ```

    Place you `docker-compose.yml` into `/etc/docker/compose/myservice`

    and call

    ```
    systemctl start docker-compose@myservice
    ```