dind 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. set -e
  3. # DinD: a wrapper script which allows docker to be run inside a docker container.
  4. # Original version by Jerome Petazzoni <jerome@docker.com>
  5. # See the blog post: https://www.docker.com/blog/docker-can-now-run-within-docker/
  6. #
  7. # This script should be executed inside a docker container in privileged mode
  8. # ('docker run --privileged', introduced in docker 0.6).
  9. # Usage: dind CMD [ARG...]
  10. # apparmor sucks and Docker needs to know that it's in a container (c) @tianon
  11. export container=docker
  12. if [ -d /sys/kernel/security ] && ! mountpoint -q /sys/kernel/security; then
  13. mount -t securityfs none /sys/kernel/security || {
  14. echo >&2 'Could not mount /sys/kernel/security.'
  15. echo >&2 'AppArmor detection and --privileged mode might break.'
  16. }
  17. fi
  18. # Mount /tmp (conditionally)
  19. if ! mountpoint -q /tmp; then
  20. mount -t tmpfs none /tmp
  21. fi
  22. # cgroup v2: enable nesting
  23. if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
  24. # move the processes from the root group to the /init group,
  25. # otherwise writing subtree_control fails with EBUSY.
  26. # An error during moving non-existent process (i.e., "cat") is ignored.
  27. mkdir -p /sys/fs/cgroup/init
  28. xargs -rn1 < /sys/fs/cgroup/cgroup.procs > /sys/fs/cgroup/init/cgroup.procs || :
  29. # enable controllers
  30. sed -e 's/ / +/g' -e 's/^/+/' < /sys/fs/cgroup/cgroup.controllers \
  31. > /sys/fs/cgroup/cgroup.subtree_control
  32. fi
  33. # Change mount propagation to shared to make the environment more similar to a
  34. # modern Linux system, e.g. with SystemD as PID 1.
  35. mount --make-rshared /
  36. if [ $# -gt 0 ]; then
  37. exec "$@"
  38. fi
  39. echo >&2 'ERROR: No command specified.'
  40. echo >&2 'You probably want to run hack/make.sh, or maybe a shell?'