docker.scm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. (define-module (gnu services docker)
  19. #:use-module (gnu services)
  20. #:use-module (gnu services configuration)
  21. #:use-module (gnu services base)
  22. #:use-module (gnu services dbus)
  23. #:use-module (gnu services shepherd)
  24. #:use-module (gnu system shadow)
  25. #:use-module (gnu packages docker)
  26. #:use-module (guix records)
  27. #:use-module (guix gexp)
  28. #:use-module (guix packages)
  29. #:export (docker-configuration
  30. docker-service-type))
  31. (define-configuration docker-configuration
  32. (docker
  33. (package docker)
  34. "Docker daemon package.")
  35. (containerd
  36. (package containerd)
  37. "containerd package."))
  38. (define %docker-accounts
  39. (list (user-group (name "docker") (system? #t))))
  40. (define (%containerd-activation config)
  41. (let ((state-dir "/var/lib/containerd"))
  42. #~(begin
  43. (use-modules (guix build utils))
  44. (mkdir-p #$state-dir))))
  45. (define (%docker-activation config)
  46. (%containerd-activation config)
  47. (let ((state-dir "/var/lib/docker"))
  48. #~(begin
  49. (use-modules (guix build utils))
  50. (mkdir-p #$state-dir))))
  51. (define (containerd-shepherd-service config)
  52. (let* ((package (docker-configuration-containerd config)))
  53. (shepherd-service
  54. (documentation "containerd daemon.")
  55. (provision '(containerd))
  56. (start #~(make-forkexec-constructor
  57. (list (string-append #$package "/bin/containerd"))
  58. #:log-file "/var/log/containerd.log"))
  59. (stop #~(make-kill-destructor)))))
  60. (define (docker-shepherd-service config)
  61. (let* ((docker (docker-configuration-docker config)))
  62. (shepherd-service
  63. (documentation "Docker daemon.")
  64. (provision '(dockerd))
  65. (requirement '(containerd
  66. dbus-system
  67. elogind
  68. file-system-/sys/fs/cgroup/blkio
  69. file-system-/sys/fs/cgroup/cpu
  70. file-system-/sys/fs/cgroup/cpuset
  71. file-system-/sys/fs/cgroup/devices
  72. file-system-/sys/fs/cgroup/memory
  73. ; TODO: file-system-/sys/fs/cgroup/pids
  74. networking
  75. udev))
  76. (start #~(make-forkexec-constructor
  77. (list (string-append #$docker "/bin/dockerd")
  78. "-p" "/var/run/docker.pid")
  79. #:pid-file "/var/run/docker.pid"
  80. #:log-file "/var/log/docker.log"))
  81. (stop #~(make-kill-destructor)))))
  82. (define docker-service-type
  83. (service-type (name 'docker)
  84. (description "Provide capability to run Docker application
  85. bundles in Docker containers.")
  86. (extensions
  87. (list
  88. (service-extension activation-service-type
  89. %docker-activation)
  90. (service-extension shepherd-root-service-type
  91. (lambda (config)
  92. (list (containerd-shepherd-service config)
  93. (docker-shepherd-service config))))
  94. (service-extension account-service-type
  95. (const %docker-accounts))))
  96. (default-value (docker-configuration))))