Is it possible to install only the docker cli and not the daemon

Docker

Docker Problem Overview


I want to have docker CLI to connect to remote daemon but do I need to install the whole engine including daemon on the local machine?

Docker Solutions


Solution 1 - Docker

First, download and unzip/untar the release for your system. Here are x86_64 binaries for mac, linux, windows.

After expanding the archive, you can find the docker CLI executable at ./docker/docker - move that file into your path, and you're done.

If you're specifically looking to install the docker CLI into a docker image, here's my Dockerfile command to do so:

ENV DOCKERVERSION=18.03.1-ce
RUN curl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKERVERSION}.tgz \
  && tar xzvf docker-${DOCKERVERSION}.tgz --strip 1 \
                 -C /usr/local/bin docker/docker \
  && rm docker-${DOCKERVERSION}.tgz

h/t to [this comment][1] [1]: https://github.com/moby/moby/issues/15360#issuecomment-255171243

Solution 2 - Docker

If you want to install Docker in Linux, then in the newest 1.12.0 release, Docker daemon and Docker client are in separate binary files.

This has been mentioned in release log:

> Split the binary into two: docker (client) and dockerd (daemon) #20639

If you are installing Docker in Mac, then Mac OS binary is client-only: resource

Solution 3 - Docker

Adding to the approach from Aaron, if you're building your own image, you can now just use multi-stage builds to copy over the docker binary from an existing external image, e.g.:

COPY --from=docker:dind /usr/local/bin/docker /usr/local/bin/

This pulls the docker binary from the public docker:dind image on Dockerhub.

See: https://docs.docker.com/develop/develop-images/multistage-build/.

Solution 4 - Docker

You can (like the other answer suggests) download it direct from Docker:

docker_url=https://download.docker.com/linux/static/stable/x86_64
docker_version=18.03.1-ce
curl -fsSL $docker_url/docker-$docker_version.tgz | \
tar zxvf - --strip 1 -C /usr/bin docker/docker

The difference from the other answer is that there is no intermediate tar file. I use this in a Dockerfile RUN layer.

Solution 5 - Docker

On Windows, you can install the CLI by itself using chocolatey package manager.

Once you have chocolatey loaded you can run this from an admin command prompt:

choco install /y docker-cli

This seems to be much more up-to-date than the Windows link provided by Aaron, for some reason. (v19 instead of v17, as of Jan 2020)

Solution 6 - Docker

If you are on Windows, you can download an up-to-date build of Docker CLI from here:

StefanScherer/docker-cli-builder

And point to a remote Docker Daemon by setting DOCKER_HOST environment variable:

$env:DOCKER_HOST = 'tcp://X.X.X.X:2375'

Please note that, in order for this to work, the Docker Daemon must be configured to expose its API over TCP. This can be done in daemon.json file:

{
    "hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2375"]
}

Solution 7 - Docker

If you are installing docker from the offical package repositories as described in these instructions, you can simply install the docker-ce-cli package and omit the installation of docker-ce and containerd.io.

Full installation sequence (for Ubuntu):

sudo apt-get update

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

# Here is the part that is different
sudo apt-get install docker-ce-cli

Solution 8 - Docker

If you want docker and docker-compose CLIs without daemon you can install them as python packages which also installs executables:

python pip install docker docker-compose 

and set the environment variable DOCKER_HOST i.e DOCKER_HOST = SSH://user@host

Solution 9 - Docker

For Ubuntu:

apt-get update
apt-get download docker.io
dpkg --fsys-tarfile docker.io_*.deb | tar xOf - ./usr/bin/docker > ./docker-cli
chmod +x ./docker-cli
rm docker.io_*.deb
shopt -s expand_aliases  # alias are not expanded in non-interactive mode (e.g. gitlab ci)
alias docker=$PWD/docker-cli

Useful in case you are working with remote docker daemon (env DOCKER_HOST).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZuriarView Question on Stackoverflow
Solution 1 - DockerAaron VView Answer on Stackoverflow
Solution 2 - DockerHaoming ZhangView Answer on Stackoverflow
Solution 3 - DockerpatricknelsonView Answer on Stackoverflow
Solution 4 - DockerstarfryView Answer on Stackoverflow
Solution 5 - DockerAdam PlocherView Answer on Stackoverflow
Solution 6 - DockerGian MarcoView Answer on Stackoverflow
Solution 7 - DockerAposhianView Answer on Stackoverflow
Solution 8 - DockerthoooooooomasView Answer on Stackoverflow
Solution 9 - Dockermr.wolleView Answer on Stackoverflow