Docker plugins are not recognized as commands when running without sudo
Asked Answered
U

3

6

I'm running

  • Ubuntu 20.04.5 LTS
  • Docker version 23.0.1, build a5ee5b1

Running the command

docker build -t some:other Dockerfile

Produces the following output:

unknown shorthand flag: 't' in -t

And

docker build

The following:

docker: 'buildx' is not a docker command.

I installed Docker as recommended from the repo: instructions

Other plugins don't work either (docker compose is not recognized either). Even then, docker info shows

  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.10.2
    Path:     /home/jpartanen/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.16.0
    Path:     /home/jpartanen/.docker/cli-plugins/docker-compose
  scan: Docker Scan (Docker Inc.)

Docker runs without sudo with the help of the docker user group, as explained in linux-postinstall. I want to run plugins without sudo as well.

I've reinstalled Docker and rebooted the machine without any change. What could be the problem?

Unlawful answered 10/2, 2023 at 15:42 Comment(0)
U
1

Make the plugins runnable for docker by creating a link:

ln -s /usr/libexec/docker/cli-plugins/ ~/.docker/cli-plugins

The command not being recognized by Docker is extra confusing because of the mismatch in commands, build vs buildx. This is because Docker Engine 23.0 set Buildx and BuildKit as the default builder on Linux. docker build is aliased to docker buildx build.

As for running without sudo, the problem is possibly caused by the plugins being installed in the wrong place. On my machine, running the command

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

installs the plugins in /usr/libexec/docker/cli-plugins/, whereas as laid out here, the plugins are usable from $HOME/.docker/cli-plugins (without sudoing).

A somewhat robust solution is to create a link as laid out above.

Unlawful answered 10/2, 2023 at 15:42 Comment(0)
C
1

The doc page about Docker Engine 23.0 also mention a flag to use the legacy builder:

DOCKER_BUILDKIT=0

This worked for me

Calpe answered 23/1 at 20:40 Comment(0)
M
0

If the plugin couldn't be run without the sudo, then it should be the permissions issue for the corresponding user. The following instructions will help.

Installation:

  • SSH to the remote machine and switch to root user
    ❯ sudo -i
  • Identify your linux architecture from client Docker version command
    ❯ docker version
    Client:
     Version:           20.10.17
     API version:       1.41
     Go version:        go1.17.11
     Git commit:        100c701
     Built:             Mon Jun  6 22:59:14 2022
     OS/Arch:           linux/arm64
     Context:           default
     Experimental:      true
    ...
    ...
  • Download the docker buildx binary of your linux arch, which is compatible to the installed Docker (Refer dependency changes under release page for compatible Docker)
    ❯ wget -nv https://github.com/docker/buildx/releases/download/v0.8.2/buildx-v0.8.2.linux-arm64
  • Create the cli-plugins folder. Replace <user> with your user, where buildx is required.
    ❯ mkdir -p /home/<user>/.docker/cli-plugins
  • Move the binary. Don't forget to rename the binary to docker-buildx like following, (It is a mandatory step)
    ❯ mv buildx-v0.8.2.linux-arm64 /home/<user>/.docker/cli-plugins/docker-buildx
  • Make the binary executable
    ❯ chmod a+x /home/<user>/.docker/cli-plugins/docker-buildx
  • Give ownership from root to your user
    ❯ chown -v -R <user> /home/<user>
  • Confirm the Docker buildx installation with Docker info command.
    ❯ docker info | head -n7
    Client:
     Context:    default
     Debug Mode: false
     Plugins:
      buildx: Docker Buildx (Docker Inc., v0.8.2)
      compose: Docker Compose (Docker Inc., v2.5.1)
    ❯
Manzano answered 2/6 at 7:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.