You can use docker container inspect command with –format option to get the docker container IP address from the host.
Syntax:
1 2 3 4 5 |
## Modern docker client: docker container inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id ## Old docker client: docker inspect --format '{{ .NetworkSettings.IPAddress }}' container_name_or_id |
Example:
1 2 3 4 5 6 7 8 9 |
## launch a new docker container docker container run -dt --name mycontainer ubuntu ## Get the ip address of the docker container from host docker container inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mycontainer ## Remove the container docker container stop mycontainer docker container prune -f |