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 | |
| 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.
| -rw-r--r-- | doc/guix.texi | 27 | ||||
| -rw-r--r-- | gnu/local.mk | 1 | ||||
| -rw-r--r-- | gnu/services/docker.scm | 94 |
3 files changed, 122 insertions, 0 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 7c6a7148300..c0cc8d4169c 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -22118,6 +22118,33 @@ The following is an example @code{dicod-service} configuration. | |||
| 22118 | %dicod-database:gcide)))) | 22118 | %dicod-database:gcide)))) |
| 22119 | @end example | 22119 | @end example |
| 22120 | 22120 | ||
| 22121 | @cindex Docker | ||
| 22122 | @subsubheading Docker Service | ||
| 22123 | |||
| 22124 | The @code{(gnu services docker)} module provides the following service. | ||
| 22125 | |||
| 22126 | @defvr {Scheme Variable} docker-service-type | ||
| 22127 | |||
| 22128 | This is the type of the service that runs @url{http://www.docker.com,Docker}, | ||
| 22129 | a daemon that can execute application bundles (sometimes referred to as | ||
| 22130 | ``containers'') in isolated environments. | ||
| 22131 | |||
| 22132 | @end defvr | ||
| 22133 | |||
| 22134 | @deftp {Data Type} docker-configuration | ||
| 22135 | This is the data type representing the configuration of Docker and Containerd. | ||
| 22136 | |||
| 22137 | @table @asis | ||
| 22138 | |||
| 22139 | @item @code{package} (default: @code{docker}) | ||
| 22140 | The Docker package to use. | ||
| 22141 | |||
| 22142 | @item @code{containerd} (default: @var{containerd}) | ||
| 22143 | The Containerd package to use. | ||
| 22144 | |||
| 22145 | @end table | ||
| 22146 | @end deftp | ||
| 22147 | |||
| 22121 | @node Setuid Programs | 22148 | @node Setuid Programs |
| 22122 | @subsection Setuid Programs | 22149 | @subsection Setuid Programs |
| 22123 | 22150 | ||
diff --git a/gnu/local.mk b/gnu/local.mk index 25363869dd9..7c319b727fe 100644 --- a/gnu/local.mk +++ b/gnu/local.mk | |||
| @@ -483,6 +483,7 @@ GNU_SYSTEM_MODULES = \ | |||
| 483 | %D%/services/desktop.scm \ | 483 | %D%/services/desktop.scm \ |
| 484 | %D%/services/dict.scm \ | 484 | %D%/services/dict.scm \ |
| 485 | %D%/services/dns.scm \ | 485 | %D%/services/dns.scm \ |
| 486 | %D%/services/docker.scm \ | ||
| 486 | %D%/services/authentication.scm \ | 487 | %D%/services/authentication.scm \ |
| 487 | %D%/services/games.scm \ | 488 | %D%/services/games.scm \ |
| 488 | %D%/services/kerberos.scm \ | 489 | %D%/services/kerberos.scm \ |
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)))) | ||
