dockerd

dockerd

dockerd는 컨테이너를 관리하는 Docker 데몬 프로세스예요. Docker 데몬을 직접 실행하고 설정하고 싶을 때 사용하는 명령이에요.

출처: 문서

본문

dockerd는 컨테이너를 관리하는 상주 프로세스예요. Docker는 데몬과 클라이언트에 서로 다른 바이너리를 사용해요. 데몬을 실행하려면 dockerd를 입력하면 돼요.

디버그 출력으로 데몬을 실행하려면 dockerd --debug를 쓰거나 daemon.json 파일에 "debug": true를 추가해요.

Usage:	dockerd [OPTIONS]

A self-sufficient runtime for containers.

Options:
      --add-runtime runtime                   Register an additional OCI compatible runtime (default [])
      --allow-direct-routing                  Allow remote access to published ports on container IP addresses
      --authorization-plugin list             Authorization plugins to load
      --bip string                            IPv4 address for the default bridge
      --bip6 string                           IPv6 address for the default bridge
  -b, --bridge string                         Attach containers to a network bridge
      --bridge-accept-fwmark string           In bridge networks, accept packets with this firewall mark/mask
      --cdi-spec-dir list                     CDI specification directories to use
      --cgroup-parent string                  Set parent cgroup for all containers
      --config-file string                    Daemon configuration file (default "/etc/docker/daemon.json")
      --containerd string                     containerd grpc address
      --containerd-namespace string           Containerd namespace to use (default "moby")
      --containerd-plugins-namespace string   Containerd namespace to use for plugins (default "plugins.moby")
      --cpu-rt-period int                     Limit the CPU real-time period in microseconds for the
                                              parent cgroup for all containers (not supported with cgroups v2)
      --cpu-rt-runtime int                    Limit the CPU real-time runtime in microseconds for the
                                              parent cgroup for all containers (not supported with cgroups v2)
      --cri-containerd                        start containerd with cri
      --data-root string                      Root directory of persistent Docker state (default "/var/lib/docker")
  -D, --debug                                 Enable debug mode
      --default-address-pool pool-options     Default address pools for node specific local networks
      --default-cgroupns-mode string          Default mode for containers cgroup namespace ("host" | "private") (default "private")
      --default-gateway ip                    Default gateway IPv4 address for the default bridge network
      --default-gateway-v6 ip                 Default gateway IPv6 address for the default bridge network
      --default-ipc-mode string               Default mode for containers ipc ("shareable" | "private") (default "private")
      --default-network-opt mapmap            Default network options (default map[])
      --default-runtime string                Default OCI runtime for containers (default "runc")
      --default-shm-size bytes                Default shm size for containers (default 64MiB)
      --default-ulimit ulimit                 Default ulimits for containers (default [])
      --dns list                              DNS server to use
      --dns-opt list                          DNS options to use
      --dns-search list                       DNS search domains to use
      --exec-opt list                         Runtime execution options
      --exec-root string                      Root directory for execution state files (default "/var/run/docker")
      --experimental                          Enable experimental features
      --feature map                           Enable feature in the daemon
      --firewall-backend string               Firewall backend to use, iptables or nftables
      --fixed-cidr string                     IPv4 subnet for the default bridge network
      --fixed-cidr-v6 string                  IPv6 subnet for the default bridge network
  -G, --group string                          Group for the unix socket (default "docker")
      --help                                  Print usage
  -H, --host list                             Daemon socket(s) to connect to
      --host-gateway-ip list                  IP addresses that the special 'host-gateway' string in --add-host resolves to.
                                              Defaults to the IP addresses of the default bridge
      --http-proxy string                     HTTP proxy URL to use for outgoing traffic
      --https-proxy string                    HTTPS proxy URL to use for outgoing traffic
      --icc                                   Enable inter-container communication for the default bridge network (default true)
      --init                                  Run an init in the container to forward signals and reap processes
      --init-path string                      Path to the docker-init binary
      --insecure-registry list                Enable insecure registry communication
      --ip ip                                 Host IP for port publishing from the default bridge network (default 0.0.0.0)
      --ip-forward                            Enable IP forwarding in system configuration (default true)
      --ip-forward-no-drop                    Do not set the filter-FORWARD policy to DROP when enabling IP forwarding
      --ip-masq                               Enable IP masquerading for the default bridge network (default true)
      --ip6tables                             Enable addition of ip6tables rules (default true)
      --iptables                              Enable addition of iptables rules (default true)
      --ipv6                                  Enable IPv6 networking for the default bridge network
      --label list                            Set key=value labels to the daemon
      --live-restore                          Enable live restore of docker when containers are still running
      --log-driver string                     Default driver for container logs (default "json-file")
      --log-format string                     Set the logging format ("text"|"json") (default "text")
  -l, --log-level string                      Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
      --log-opt map                           Default log driver options for containers (default map[])
      --max-concurrent-downloads int          Set the max concurrent downloads (default 3)
      --max-concurrent-uploads int            Set the max concurrent uploads (default 5)
      --max-download-attempts int             Set the max download attempts for each pull (default 5)
      --metrics-addr string                   Set default address and port to serve the metrics api on
      --mtu int                               Set the MTU for the default "bridge" network (default 1500)
      --network-control-plane-mtu int         Network Control plane MTU (default 1500)
      --no-new-privileges                     Set no-new-privileges by default for new containers
      --no-proxy string                       Comma-separated list of hosts or IP addresses for which the proxy is skipped
      --node-generic-resource list            Advertise user-defined resource
  -p, --pidfile string                        Path to use for daemon PID file (default "/var/run/docker.pid")
      --raw-logs                              Full timestamps without ANSI coloring
      --registry-mirror list                  Preferred registry mirror
      --rootless                              Enable rootless mode; typically used with RootlessKit
      --seccomp-profile string                Path to seccomp profile. Set to "unconfined" to disable the default seccomp profile (default "builtin")
      --selinux-enabled                       Enable selinux support
      --shutdown-timeout int                  Set the default shutdown timeout (default 15)
  -s, --storage-driver string                 Storage driver to use
      --storage-opt list                      Storage driver options
      --swarm-default-advertise-addr string   Set default address or interface for swarm advertised address
      --tls                                   Use TLS; implied by --tlsverify
      --tlscacert string                      Trust certs signed only by this CA (default "~/.docker/ca.pem")
      --tlscert string                        Path to TLS certificate file (default "~/.docker/cert.pem")
      --tlskey string                         Path to TLS key file (default "~/.docker/key.pem")
      --tlsverify                             Use TLS and verify the remote
      --userland-proxy                        Use userland proxy for loopback traffic (default true)
      --userland-proxy-path string            Path to the userland proxy binary
      --userns-remap string                   User/Group setting for user namespaces
      --validate                              Validate daemon configuration and exit
  -v, --version                               Print version information and quit

[]가 붙은 옵션은 여러 번 지정할 수 있어요.

참고: 실험 기능 켜기--experimental 플래그로 dockerd를 시작하거나 daemon.json 파일에 "experimental": true를 추가해서 실험 기능을 켤 수 있어요.

환경 변수

dockerd 데몬이 지원하는 환경 변수는 다음과 같아요. 일부는 Docker 데몬과 docker CLI 양쪽 모두가 지원해요 (docker CLI 지원 환경 변수는 Environment variables 참고).

변수 설명
DOCKER_CERT_PATH 인증 키 위치예요. docker CLI와 dockerd 데몬 양쪽이 사용해요.
DOCKER_DRIVER 사용할 스토리지 드라이버예요.
DOCKER_RAMDISK 설정되면 pivot_root를 비활성화해요.
DOCKER_TLS_VERIFY 설정되면 Docker가 TLS를 사용하고 원격을 검증해요. CLI와 데몬 양쪽이 사용해요.
DOCKER_TMPDIR 데몬이 만드는 임시 파일 위치예요.
HTTP_PROXY NoProxy로 재정의되지 않는 한 HTTP 요청의 프록시 URL이에요.
HTTPS_PROXY NoProxy로 재정의되지 않는 한 HTTPS 요청의 프록시 URL이에요.
MOBY_DISABLE_PIGZ 설치돼 있어도 이미지 풀 시 레이어 병렬 해제에 unpigz를 쓰지 않게 해요.
NO_PROXY 프록시에서 제외할 호스트를 쉼표로 구분한 값이에요.

프록시 설정

HTTP 프록시 서버 뒤에 있다면(예: 기업 환경) 이미지 풀·푸시 같은 작업에 프록시 서버를 쓰도록 Docker 데몬을 설정해야 할 수 있어요. 데몬은 세 가지 방식으로 설정할 수 있어요.

  • 환경 변수 사용 (HTTP_PROXY, HTTPS_PROXY, NO_PROXY)
  • 데몬 설정 파일의 http-proxy, https-proxy, no-proxy 필드 사용 (Docker Engine 23.0 이상)
  • --http-proxy, --https-proxy, --no-proxy 커맨드라인 옵션 사용 (Docker Engine 23.0 이상)

커맨드라인과 설정 파일 옵션이 환경 변수보다 우선해요.

데몬 소켓 옵션

Docker 데몬은 세 가지 유형의 소켓(unix, tcp, fd)으로 Docker Engine API 요청을 수신할 수 있어요.

기본적으로 /var/run/docker.sockunix 도메인 소켓(IPC 소켓)이 만들어지고, root 권한이나 docker 그룹 멤버십이 필요해요.

원격으로 Docker 데몬에 접근하려면 tcp 소켓을 활성화해야 해요. TCP 소켓을 쓰면 기본적으로 Docker 데몬에 암호화·인증 없는 직접 접근을 허용하므로, 내장 HTTPS 암호화 소켓을 쓰거나 앞에 보안 웹 프록시를 두어 데몬을 보호해야 해요. 모든 네트워크 인터페이스의 포트 2375에서 수신하려면 -H tcp://0.0.0.0:2375를, 특정 인터페이스의 IP로 수신하려면 그 IP 주소를 쓰면 돼요. 관례상 암호화되지 않은 통신은 2375, 암호화된 통신은 2376 포트를 사용해요.

참고: HTTPS 암호화 소켓을 사용한다면 TLS 1.0 이상만 지원돼요. 보안상 SSLv3 이하 프로토콜은 지원되지 않아요.

systemd 기반 시스템에서는 dockerd -H fd://로 systemd 소켓 활성화를 통해 데몬과 통신할 수 있어요. fd://는 대부분의 설정에서 동작하지만, dockerd -H fd://3처럼 개별 소켓을 지정할 수도 있어요. 지정한 소켓 활성화 파일이 없으면 데몬은 종료돼요.

-H 옵션을 여러 번 써서 동시에 여러 소켓을 수신하도록 설정할 수 있어요.

$ sudo dockerd -H unix:///var/run/docker.sock -H tcp://192.168.59.106 -H tcp://10.10.10.2

Docker 클라이언트는 DOCKER_HOST 환경 변수로 -H 플래그를 설정해요. 다음 중 하나를 사용해요.

$ docker -H tcp://0.0.0.0:2375 ps
$ export DOCKER_HOST="tcp://0.0.0.0:2375"
$ docker ps

DOCKER_TLS_VERIFY 환경 변수를 빈 문자열이 아닌 값으로 설정하는 건 --tlsverify 플래그를 설정하는 것과 같아요.

$ docker --tlsverify ps
# or
$ export DOCKER_TLS_VERIFY=1
$ docker ps

Docker 클라이언트는 HTTP_PROXY, HTTPS_PROXY, NO_PROXY 환경 변수(또는 소문자 버전)를 따르고, HTTPS_PROXYHTTP_PROXY보다 우선해요.

Docker 클라이언트는 SSH로 원격 데몬에 연결하는 것도 지원해요.

$ docker -H ssh://[email protected]:22/var/run/docker.sock ps
$ docker -H ssh://[email protected]:22 ps
$ docker -H ssh://[email protected] ps
$ docker -H ssh://example.com ps

SSH 연결을 쓰려면 공개 키 인증으로 원격 호스트에 도달하도록 ssh를 설정해야 해요. 비밀번호 인증은 지원되지 않아요. 키가 패스프레이즈로 보호돼 있으면 ssh-agent를 설정해야 해요.

경고: 기본 docker 데몬 바인딩을 TCP 포트나 Unix docker 사용자 그룹으로 바꾸면 비루트 사용자가 호스트의 루트 접근을 얻을 수 있어 보안 위험이 생겨요. docker에 대한 접근을 반드시 통제하세요. TCP 포트에 바인딩하면 그 포트에 접근할 수 있는 사람은 누구나 전체 Docker 접근 권한을 갖게 돼요.

스토리지 드라이버

-s/--storage-driver로 스토리지 드라이버를 선택할 수 있고, 기본값은 호스트 플랫폼과 설정에 따라 달라요. 데몬은 컨테이너 계층과 이미지를 저장하는 데 이 드라이버를 사용해요. 각 스토리지 드라이버는 고유한 옵션(--storage-opt)을 지원하며, 성능·안정성·보안 특성이 조금씩 달라요.

데몬 DNS 옵션

--dns, --dns-search, --dns-opt 옵션으로 데몬의 DNS 설정을 지정할 수 있어요. 기본 브리지 네트워크의 컨테이너가 사용할 DNS 서버(--dns), 검색 도메인(--dns-search), DNS 옵션(--dns-opt)을 정해요.

안전하지 않은 레지스트리 (Insecure registries)

--insecure-registry 옵션으로 HTTPS 없이(또는 자체 서명 인증서로) 통신할 레지스트리를 지정할 수 있어요. 이 옵션은 개발·테스트 환경에서 로컬 레지스트리를 쓸 때 유용해요. 기본적으로 Docker는 HTTPS 레지스트리만 신뢰해요.

기본 ulimit 설정

--default-ulimit 옵션으로 새 컨테이너에 적용할 기본 ulimit 값을 지정할 수 있어요. --default-ulimit nproc=1024:2048 --default-ulimit nofile=1024:2048처럼 여러 번 지정할 수 있어요.

사용자 네임스페이스

--userns-remap 옵션으로 컨테이너에 사용자 네임스페이스를 적용해 컨테이너 프로세스가 호스트의 루트 권한을 갖지 않게 할 수 있어요.

호스트 게이트웨이 IP

--host-gateway-ip--add-host의 특별한 host-gateway 문자열로 컨테이너에서 호스트에 접근할 IP를 구성할 수 있어요.

데몬 설정 파일

기본 구성 파일은 /etc/docker/daemon.json이에요 (--config-file로 변경). 데몬은 이 JSON 파일에서 설정을 읽고, 대부분의 CLI 플래그를 파일의 키-값으로 지정할 수 있어요.

여러 데몬 실행

dockerd --data-root, --exec-root, --pidfile, --host 등을 조합해 같은 호스트에서 여러 Docker 데몬을 실행할 수 있어요. 저장소 상태와 소켓 경로를 분리해야 충돌하지 않아요.

더 알아보기