docker / cli

The Docker CLI
Apache License 2.0
4.94k stars 1.93k forks source link

docker installed by snap doesn't work with DOCKER_CONFIG env #3961

Closed yongxiu closed 1 year ago

yongxiu commented 1 year ago

Description

I have two ubuntu 20.04 servers, one have docker installed using 'snap install docker', another one followed https://docs.docker.com/engine/install/ubuntu/

I found the one installed with snap will fail to pull with credential error when providing DOCKER_CONFIG environment variable, it can read /root/snap/docker/2285/.docker successfully.

If I specify DOCKER_CONFIG when running docker pull, it will fail to pull and print errors, even though this directory's content is exactly same as /root/snap/docker/2285/.docker

$ DOCKER_CONFIG=/abc/ docker pull gcr.io/anthos-baremetal-release/ais@sha256:dbb50745df164659dc5701cfeb3ffb540f67b8defc8aacb5ed9062a11953114b
Error response from daemon: unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication

The machine with normal docker installed doesn't have this issue.

Reproduce

  1. Have a ubuntu 20.04
  2. snap install docker
  3. docker login gcr.io and input username and password
  4. cp /root/snap/docker/current/.docker/ /abc/
  5. chmod 777 /abc/
  6. chmod 777 /abc/config.json
  7. DOCKER_CONFIG=/abc/ docker pull gcr.io/anthos-baremetal-release/ais@sha256:dbb50745df164659dc5701cfeb3ffb540f67b8defc8aacb5ed9062a11953114b

Expected behavior

docker pull successfully

docker version

Client:
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.16.15
 Git commit:        100c70180f
 Built:             Thu Sep 22 06:21:41 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.15
  Git commit:       a89b842
  Built:            Thu Sep 22 06:22:13 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.6.6
  GitCommit:        10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc:
  Version:          1.1.2
  GitCommit:
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client:
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.16.15
 Git commit:        100c70180f
 Built:             Thu Sep 22 06:21:41 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.15
  Git commit:       a89b842
  Built:            Thu Sep 22 06:22:13 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.6.6
  GitCommit:        10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc:
  Version:          1.1.2
  GitCommit:
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
root@instance-5:~/snap/docker/current/.docker# docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.8.2)
  compose: Docker Compose (Docker Inc., v2.5.0)

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 4
 Server Version: 20.10.17
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: active
  NodeID: tqxjsvnbccmenotjax8jrjrq2
  Is Manager: true
  ClusterID: jm92btnsq0q5x2hkoapqk6ans
  Managers: 1
  Nodes: 1
  Default Address Pool: 10.0.0.0/8
  SubnetSize: 24
  Data Path Port: 4789
  Orchestration:
   Task History Retention Limit: 5
  Raft:
   Snapshot Interval: 10000
   Number of Old Snapshots to Retain: 0
   Heartbeat Tick: 1
   Election Tick: 10
  Dispatcher:
   Heartbeat Period: 5 seconds
  CA Configuration:
   Expiry Duration: 3 months
   Force Rotate: 0
  Autolock Managers: false
  Root Rotation In Progress: false
  Node Address: 10.168.0.75
  Manager Addresses:
   10.168.0.75:2377
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc version:
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.15.0-1025-gcp
 Operating System: Ubuntu Core 18
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 15.62GiB
 Name: instance-5
 ID: MEWI:FSZV:B25G:JCUO:OWD5:UHPC:IJOT:OY76:UOCC:3547:NKVQ:ZVRQ
 Docker Root Dir: /var/snap/docker/common/var-lib-docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional Info

No response

yongxiu commented 1 year ago

nvm, I found this is caused by docker installed by snap is in strict confinement mode: https://snapcraft.io/docs/snap-confinement, so it can't read the directory I provided.