'do not add `name` key value when generating docker compose file using `docker compose config` command
There seems to be a discrepancy in the implementation between docker compose CLI command and docker-compose CLI. Although they follow the same specification for Compose.
Services
As a simple example, I have two compose files
docker-compose.hello-world.yml
version: '3.7'
services:
hello:
image: hello-world:nano-server
container_name: hello_world
docker-compose.base.yml
very simple base file
version: '3.7'
volumes:
dummy-vol:
I can override them using the -f flag as follows:
docker compose -f docker-compose.hello-world.yml -f docker-compose.base.yml config > docker-compose.yml
Discrepancy
If one uses the above command using the docker compose CLI in built in the Docker Engine:
docker compose -f docker-compose.hello-world.yml -f docker-compose.base.yml config
The resultant configuration generated is:
here test-con is just the name of the directory I have the files in
name: test-con
services:
hello:
container_name: hello_world
image: hello-world:nano-server
networks:
default: null
networks:
default:
name: test-con_default
However when using the docker-compose CLI,
docker-compose -f docker-compose.hello-world.yml -f docker-compose.base.yml config
generates the following output:
services:
hello:
container_name: hello_world
image: hello-world:nano-server
version: '3.7'
volumes:
test: {}
As you can see name key value is not generated with docker-compose.
Is there a way to suppress generating the name key-value from docker compose CLI?
System Specs
docker version
Client:
Version: 20.10.12
API version: 1.41
Go version: go1.17.5
Git commit: e91ed5707e
Built: Mon Dec 13 22:31:40 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.12
API version: 1.41 (minimum version 1.12)
Go version: go1.17.5
Git commit: 459d0dfbbb
Built: Mon Dec 13 22:30:43 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.6.1
GitCommit: 10f428dac7cec44c864e1b830a4623af27a9fc70.m
runc:
Version: 1.1.0
GitCommit: v1.1.0-0-g067aaf85
docker-init:
Version: 0.19.0
GitCommit: de40ad0
docker compose version
Docker Compose version 2.3.3
docker-compose version
docker-compose version 1.29.2, build unknown
docker-py version: 5.0.3
CPython version: 3.10.2
OpenSSL version: OpenSSL 1.1.1m 14 Dec 2021
Solution 1:[1]
This discrepancy is resolved when upgraded to v2.4.1 for docker.
Upon conducting the same test:
docker-compose -f docker-compose.hello-world.yml config > std.yml
as well as
docker compose -f docker-compose.hello-world.yml config > cli.yml
and checking to see if there is any difference using diff
diff std.yml cli.yml
now provides the same configuration in both tools
name: test-com
services:
hello:
container_name: hello_world
image: hello-world:nano-server
networks:
default: null
networks:
default:
name: test-com_default
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shan-Desai |
