Search code examples
linuxdockeropensusesystemctlsles

How to configure systemctl service for docker installed from binaries?


I installed docker from binaries on SLES 15 x86_64 (https://docs.docker.com/engine/install/binaries/#install-static-binaries). And now I need to configure boot on start up and rootless launch. But I have no docker.service. And I don't understand how to configure it manually.

Thank you.


Solution

  • Normally I'd suggest to enable Container Module 12 x86_64 (aka sle-module-containers/12/x86_64) as described here but I think you have your reasons for not using it.

    You need to create the docker.service and docker.socket files in the /etc/systemd/system folder as described in the documentation.

    docker.service content can found here and it's currently:

    [Unit]
    Description=Docker Application Container Engine
    Documentation=https://docs.docker.com
    After=network-online.target docker.socket firewalld.service containerd.service
    Wants=network-online.target containerd.service
    Requires=docker.socket
    
    [Service]
    Type=notify
    # the default is not to use systemd for cgroups because the delegate issues still
    # exists and systemd currently does not support the cgroup feature set required
    # for containers run by docker
    ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
    ExecReload=/bin/kill -s HUP $MAINPID
    TimeoutStartSec=0
    RestartSec=2
    Restart=always
    
    # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
    # Both the old, and new location are accepted by systemd 229 and up, so using the old location
    # to make them work for either version of systemd.
    StartLimitBurst=3
    
    # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
    # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
    # this option work for either version of systemd.
    StartLimitInterval=60s
    
    # Having non-zero Limit*s causes performance problems due to accounting overhead
    # in the kernel. We recommend using cgroups to do container-local accounting.
    LimitNOFILE=infinity
    LimitNPROC=infinity
    LimitCORE=infinity
    
    # Comment TasksMax if your systemd version does not support it.
    # Only systemd 226 and above support this option.
    TasksMax=infinity
    
    # set delegate yes so that systemd does not reset the cgroups of docker containers
    Delegate=yes
    
    # kill only the docker process, not all processes in the cgroup
    KillMode=process
    OOMScoreAdjust=-500
    
    [Install]
    WantedBy=multi-user.target
    

    docker.socket can be found here and it's currently:

    [Unit]
    Description=Docker Socket for the API
    
    [Socket]
    # If /var/run is not implemented as a symlink to /run, you may need to
    # specify ListenStream=/var/run/docker.sock instead.
    ListenStream=/run/docker.sock
    SocketMode=0660
    SocketUser=root
    SocketGroup=docker
    
    [Install]
    WantedBy=sockets.target