diff options
| author | Danny Milosavljevic <dannym@scratchpost.org> | 2018-12-31 00:39:02 +0100 |
|---|---|---|
| committer | Danny Milosavljevic <dannym@scratchpost.org> | 2019-01-10 03:00:55 +0100 |
| commit | 8af4c335e32fbed7556a4cd7f26f93bc66afaace (patch) | |
| tree | 2265b19aca1e5cd77a9ae43d0a47209b7fffdf63 /gnu/services/docker.scm | |
| parent | f87ea24a821c1cee8f9a8f0d38d7f02fa43d8383 (diff) | |
services: Add docker.
* gnu/services/docker.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
* doc/guix.texi (Miscellaneous Services): Document the service.
Diffstat (limited to 'gnu/services/docker.scm')
| -rw-r--r-- | gnu/services/docker.scm | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/gnu/services/docker.scm b/gnu/services/docker.scm new file mode 100644 index 00000000000..6d270831b32 --- /dev/null +++ b/gnu/services/docker.scm | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | ||
| 2 | ;;; Copyright © 2018 Danny Milosavljevic <dannym@scratchpost.org> | ||
| 3 | ;;; | ||
| 4 | ;;; This file is part of GNU Guix. | ||
| 5 | ;;; | ||
| 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | ;;; under the terms of the GNU General Public License as published by | ||
| 8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | ;;; your option) any later version. | ||
| 10 | ;;; | ||
| 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | ;;; GNU General Public License for more details. | ||
| 15 | ;;; | ||
| 16 | ;;; You should have received a copy of the GNU General Public License | ||
| 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | (define-module (gnu services docker) | ||
| 20 | #:use-module (gnu services) | ||
| 21 | #:use-module (gnu services configuration) | ||
| 22 | #:use-module (gnu services base) | ||
| 23 | #:use-module (gnu services dbus) | ||
| 24 | #:use-module (gnu services shepherd) | ||
| 25 | #:use-module (gnu system shadow) | ||
| 26 | #:use-module (gnu packages docker) | ||
| 27 | #:use-module (guix records) | ||
| 28 | #:use-module (guix gexp) | ||
| 29 | #:use-module (guix packages) | ||
| 30 | |||
| 31 | #:export (docker-configuration | ||
| 32 | docker-service-type)) | ||
| 33 | |||
| 34 | (define-configuration docker-configuration | ||
| 35 | (docker | ||
| 36 | (package docker) | ||
| 37 | "Docker daemon package.") | ||
| 38 | (containerd | ||
| 39 | (package containerd) | ||
| 40 | "containerd package.")) | ||
| 41 | |||
| 42 | (define %docker-accounts | ||
| 43 | (list (user-group (name "docker") (system? #t)))) | ||
| 44 | |||
| 45 | (define (%containerd-activation config) | ||
| 46 | (let ((state-dir "/var/lib/containerd")) | ||
| 47 | #~(begin | ||
| 48 | (use-modules (guix build utils)) | ||
| 49 | (mkdir-p #$state-dir)))) | ||
| 50 | |||
| 51 | (define (%docker-activation config) | ||
| 52 | (%containerd-activation config) | ||
| 53 | (let ((state-dir "/var/lib/docker")) | ||
| 54 | #~(begin | ||
| 55 | (use-modules (guix build utils)) | ||
| 56 | (mkdir-p #$state-dir)))) | ||
| 57 | |||
| 58 | (define (containerd-shepherd-service config) | ||
| 59 | (let* ((package (docker-configuration-containerd config))) | ||
| 60 | (shepherd-service | ||
| 61 | (documentation "containerd daemon.") | ||
| 62 | (provision '(containerd)) | ||
| 63 | (start #~(make-forkexec-constructor | ||
| 64 | (list (string-append #$package "/bin/containerd")))) | ||
| 65 | (stop #~(make-kill-destructor))))) | ||
| 66 | |||
| 67 | (define (docker-shepherd-service config) | ||
| 68 | (let* ((docker (docker-configuration-docker config))) | ||
| 69 | (shepherd-service | ||
| 70 | (documentation "Docker daemon.") | ||
| 71 | (provision '(dockerd)) | ||
| 72 | (requirement '(containerd)) | ||
| 73 | (start #~(make-forkexec-constructor | ||
| 74 | (list (string-append #$docker "/bin/dockerd") | ||
| 75 | "-p" "/var/run/docker.pid") | ||
| 76 | #:pid-file "/var/run/docker.pid" | ||
| 77 | #:log-file "/var/log/docker.log")) | ||
| 78 | (stop #~(make-kill-destructor))))) | ||
| 79 | |||
| 80 | (define docker-service-type | ||
| 81 | (service-type (name 'docker) | ||
| 82 | (description "Provide capability to run Docker application | ||
| 83 | bundles in Docker containers.") | ||
| 84 | (extensions | ||
| 85 | (list | ||
| 86 | (service-extension activation-service-type | ||
| 87 | %docker-activation) | ||
| 88 | (service-extension shepherd-root-service-type | ||
| 89 | (lambda args | ||
| 90 | (list (apply containerd-shepherd-service args) | ||
| 91 | (apply docker-shepherd-service args)))) | ||
| 92 | (service-extension account-service-type | ||
| 93 | (const %docker-accounts)))) | ||
| 94 | (default-value (docker-configuration)))) | ||
