DEV Community

Aisuko
Aisuko

Posted on

We may not need to install docker daemon on our local system

I'd like to share some interesting things of using the Docker command.

The environment which I have to list at below:

  • macOS Big Sur Version 11.3.1 with multiple accounts
  • Homebrew 3.1.8
  • docker client v20.10.6
  • Ubuntu 20.04 and which was installed the latest version of docker client and docker daemon

In my local environment, macOS Big Sur Version 11.3.1. We do not need to install Docker desktop for mac on it, only docker client is enough for me.

Why I do not like install docker daemon on my local machine?

The Docker desktop for mac installs docker client, docker daemon and a Kubernetes cluster feature on my macOS. I have a situation when I use my old mac(2014) with 8GB memory, these components account too much resource, and several active containers and Goland IDE will make my old mac slow.

So, I'd like to only install docker client on my machine and connect to remote docker daemon to manage containers.

Install Homebrew anywhere

And for my situation, I'd like to use the standard user who without extra privilege permission.

The issue someone may interest in below:
https://superuser.com/questions/619498/can-i-install-homebrew-without-sudo-privileges

And we can install Homebrew without privilege with this script:

mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
Enter fullscreen mode Exit fullscreen mode

And do not forget to add the PATH of Homebrew to the ~/.zshrc file if you use the oh-my-zsh like me.

Add the environments and PATH of Homebrew into the ~/.zshrc

HOMEBREW_CELLAR=${HOME}/homebrew/Cellar
HOMEBREW_PREFIX=${HOME}/homebrew
# $PATH for brew without root privileged
export PATH=$HOMEBREW_PREFIX/bin:$PATH
Enter fullscreen mode Exit fullscreen mode

And the source ~/.zshrc without restarting your terminal, that brew can be using as the standard user.

Install docker client with Homebrew

We can use the command brew search docker to get information for docker on brew channel

➜  ~ brew search docker
==> Formulae
docker ✔                         docker-credential-helper-ecr     docker-machine-driver-vmware     docker-squash
docker-clean                     docker-gen                       docker-machine-driver-vultr      docker-swarm
docker-completion                docker-ls                        docker-machine-driver-xhyve      docker2aci
docker-compose                   docker-machine                   docker-machine-nfs               dockerize
docker-compose-completion        docker-machine-completion        docker-machine-parallels         lazydocker
docker-credential-helper         docker-machine-driver-hyperkit   docker-slim
==> Casks
docker                                      docker-toolbox                              homebrew/cask-versions/docker-edge
➜  ~ 
Enter fullscreen mode Exit fullscreen mode

And we can install docker client by using brew install docker command

➜  ~ docker version
Client: Docker Engine - Community
 Version:           20.10.6
 API version:       1.41
 Go version:        go1.16.3
 Git commit:        370c289
 Built:             Mon Apr 12 14:44:32 2021
 OS/Arch:           darwin/amd64
 Context:           default
 Experimental:      true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Enter fullscreen mode Exit fullscreen mode

Creating docker context

More information about docker context https://docs.docker.com/engine/context/working-with-contexts/

As the document said:

A single Docker CLI can have multiple contexts and each context contains all of the endpoint and security information required to manage a different cluster or node. The docker context command makes it easy to configure these contexts and switch between them.

➜  ~ docker context ls
NAME        DESCRIPTION                               DOCKER ENDPOINT               KUBERNETES ENDPOINT   ORCHESTRATOR
default *   Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                         swarm
Enter fullscreen mode Exit fullscreen mode

We can connect to the remote machine(there needs to use ss key login not the password)

And create the Docker context use the command below:

docker context create example-name --docker "host=ssh://username@host:port"
Enter fullscreen mode Exit fullscreen mode

Always include the user name in the Docker endpoint address, even if it is the same as the local user name. If you omit the port, it defaults to 22.

Change the Docker context we want to use:

docker context use example-name

# Check the images on the remote machine
docker images
Enter fullscreen mode Exit fullscreen mode

Conclusion

We can use docker context command to connect to the remote Docker daemon was installed on GNU-Linux or other OS. This can
help us to use any remote Docker daemon we want to use. And do not need to install Docker daemon in local environment.

Top comments (0)