Setup
docker --version
Docker version 1.10.0-rc2, build c1cdc6e
It seems that Docker CLI doesn't reject the network name which, for example, has - in them, such as
docker network create --subnet 172.18.15.0/20 test-1
docker inspect test-1
docker network inspect test-1
all works just fine. No problem.
However, when I tried to do
docker inspect -f "{{.NetworkSettings.Networks.test-1.IPAddress}}" test-1
It complains
Template parsing error: template: :1: bad character U+002D '-'
I would suggest that we formally define the naming convention and enforce at the source, i.e. when users create the networks.
I would suggest that we formally define the naming convention and enforce at the source, i.e. when users create the networks.
If we do this, we'll break backward capabilities that we can't create network with - in name anymore.
Template parsing error: template: :1: bad character U+002D '-'
The above error is because docker inspect -f format the output using the given golang template. According to the specs in http://golang.org/pkg/text/template/#Arguments, the key must be alphanumeric. But you can use index function in your template to get the correct value if you defined such network name.
root@docker-1:/home/vagrant# docker network create --subnet 172.18.15.0/20 test-1
a76129bd3bd44856ede8b8f2ee27639b77bf47c10024a664d4ef944eb3bb6c2e
root@docker-1:/home/vagrant# docker run --net=test-1 --name=ubuntu -d ubuntu sleep 3333
ea06be2c094e3c51d41507b12bb3fe5f7c3e6c0234530d39703798a82754ba56
root@docker-1:/home/vagrant# docker inspect -f "{{with index .NetworkSettings.Networks \"test-1\"}}{{.IPAddress}}{{end}}" ubuntu
172.18.0.2
@jianghaitao It has been detected that this issue has not received any activity in over 6 months. Can you please let us know if it is still relevant:
Thank you!
This issue will be automatically closed in 1 week unless it is commented on.
For more information please refer to https://github.com/docker/libnetwork/issues/1926
Most helpful comment
If we do this, we'll break backward capabilities that we can't create network with
-in name anymore.The above error is because
docker inspect -fformat the output using the given golang template. According to the specs in http://golang.org/pkg/text/template/#Arguments, the key must be alphanumeric. But you can useindexfunction in your template to get the correct value if you defined such network name.