cli
cli copied to clipboard
Can't handle config file properly when it's a relative symlink
Description
When the config file is a relative symlink, docker cli can't handle it properly. Every config file writing operation, like docker login or docker context use, will take no effect on the real config file, but instead it creates a new file that relative to the current working directory.
Reproduce
In a fresh new docker environment:
$ mkdir ~/.docker
$ echo '{}' > ~/.docker/config-company.json
$ ln -s config-company.json ~/.docker/config.json # this create a relative symlink
$ ls -l ~/.docker/config.json
lrwxrwxrwx 1 user group 22 Jul 23 21:37 /home/user/.docker/haha.json -> config-company.json
$ cat ~/.docker/config.json
{}
$ docker login -u <user>
Password:
Login Succeeded
$ cat ~/.docker/config.json
{}
# below is the file that docker cli actually created and wrote to, relative to the current working directory.
$ cat ./config-company.json
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "xxxxxxxx"
}
}
}
Expected behavior
docker cli should write to the absolute path of the symlink target.
docker version
Client: Docker Engine - Community
Version: 27.0.3
API version: 1.46
Go version: go1.21.11
Git commit: 7d4bcd8
Built: Sat Jun 29 00:02:23 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 27.0.3
API version: 1.46 (minimum version 1.24)
Go version: go1.21.11
Git commit: 662f78c
Built: Sat Jun 29 00:02:23 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.7.19
GitCommit: 2bf793ef6dc9a18e00cb12efb64355c2c9d5eb41
runc:
Version: 1.7.19
GitCommit: v1.1.13-0-g58aa920
docker-init:
Version: 0.19.0
GitCommit: de40ad0
docker info
Client: Docker Engine - Community
Version: 27.0.3
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.15.1
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.28.1
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 40
Server Version: 27.0.3
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 2bf793ef6dc9a18e00cb12efb64355c2c9d5eb41
runc version: v1.1.13-0-g58aa920
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.8.0-38-generic
Operating System: Ubuntu 24.04 LTS
OSType: linux
Architecture: x86_64
CPUs: 12
Total Memory: 31.26GiB
Name: workstation
ID: ed0b07d9-611f-4637-a1f8-1d9403688a32
Docker Root Dir: /var/lib/docker
Debug Mode: false
...
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Additional Info
No response