Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

docker inspect --format doesn't work in Windows #433

Open
zkanda opened this issue Feb 25, 2016 · 13 comments
Open

docker inspect --format doesn't work in Windows #433

zkanda opened this issue Feb 25, 2016 · 13 comments

Comments

@zkanda
Copy link

zkanda commented Feb 25, 2016

Hello I'm trying to use docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' from docker inspect examples. But it's giving me these error:
Template parsing error: template: :1: unexpected unclosed action in range

I'm using the docker quickstart terminal.

I created it here because that same command works in Linux machines.

@thaJeztah
Copy link
Member

Wondering; does it work if you use double quotes? " instead of '?

@zkanda
Copy link
Author

zkanda commented Feb 25, 2016

Doesn't work with double quotes as well.

@thaJeztah
Copy link
Member

alright - can you open an issue in the https://github.com/docker/docker/issues issue-tracker? This sounds like an issue in the Docker Engine (or a combination of Docker Engine and the environment the CLI runs in)

@calavera
Copy link

calavera commented Mar 1, 2016

it could be an issue in how Go parses the format in Windows. The engine doesn't do anything different to parse the format whether it's linux or windows.

@Gmanweb
Copy link

Gmanweb commented Aug 16, 2016

@thaJeztah Same problem but when I change ' to " it work . Thanks
docker inspect --format "{{ .NetworkSettings.IPAddress }}" zookeeper

@DanyEle
Copy link

DanyEle commented Feb 13, 2020

[Good old necro posting]

Thank you @Gmanweb . The following command does indeed do the job still in 2020:

docker inspect --format "{{ .NetworkSettings.IPAddress }}" <container_name>

@DanyEle
Copy link

DanyEle commented Feb 15, 2020

Still, there doesn't seem to be a way to ping a Linux Docker containing from a host Windows machine. Anyone found a way to do that?

@thaJeztah
Copy link
Member

The container's IP address is an internal IP address; to ping/reach the container, use port mapping to publish its port(s);-p <host-port>:<container-port> (e.g. -p 8080:80 to map container port 80 to port 8080 on the docker hosts network interface. Then connect to the container at <host ip address>:8080.

@DanyEle
Copy link

DanyEle commented Feb 15, 2020

The container's IP address is an internal IP address; to ping/reach the container, use port mapping to publish its port(s);-p <host-port>:<container-port> (e.g. -p 8080:80 to map container port 80 to port 8080 on the docker hosts network interface. Then connect to the container at <host ip address>:8080.

Already tried this solution, but it didn't work. I'm running a Flask app within my Docker container at port 5000 and I would like to expose it at that same port, so that it would be reachable from my local Windows 10 machine.

The thing is that I can't even ping my container's IP address in the first place.

@thaJeztah
Copy link
Member

The thing is that I can't even ping my container's IP address in the first place.

If it's a linux container, the container runs inside a lightweight VM, and that IP address isn't accessible from your host.
Make sure the app inside the container is listening on 0.0.0.0, and (assuming you're using Docker Desktop) when publishing the port (-p 5000:5000), is should be accessible on localhost:5000 from your Windows machine

@DanyEle
Copy link

DanyEle commented Feb 17, 2020

The thing is that I can't even ping my container's IP address in the first place.

If it's a linux container, the container runs inside a lightweight VM, and that IP address isn't accessible from your host.
Make sure the app inside the container is listening on 0.0.0.0, and (assuming you're using Docker Desktop) when publishing the port (-p 5000:5000), is should be accessible on localhost:5000 from your Windows machine

Finally got it working with this hint, thank you so much!!

In the Dockerfile, I specified the following command to start the flask app:

ENTRYPOINT ["flask", "run", "--host=0.0.0.0"]

And then, I ran the container with the following command:

docker run -p 5000:5000 <image_name>

Finally, I was able to access my webapp in the browser!

image

@j0ruge
Copy link

j0ruge commented Mar 31, 2020

On Windows 10
docker image inspect --format='{{index .Config.Labels \"maintainer\"}}' <image_name>

@raghav-axero
Copy link

As suggested above, it worked after replacing single quotes with double quotes:

docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants