0

I used the Docker command to run a container.

docker run -itd -p 8001:801 --name centos7_01 centos:centos7 /bin/bash
  1. Can I see the IP address of the host in the container?
  2. Can I write the port of the host in the port map consistent with the port of the container?
Lina Gong
  • 9
  • 4
  • you can see the IP address of the host in the container by running the command "ip addr show" within the container – Mech Dec 08 '22 at 03:45
  • you can pass the host IP as environment to container `docker run --env HST="$(hostname -i)"`. –  Dec 08 '22 at 09:15
  • You usually don't need it, and it may be tricky to find it (for example on Docker Desktop). I've linked to a question that describes a couple of approaches, but if you're just trying to make a call to a non-container process, see the question that one is linked to. – David Maze Dec 08 '22 at 11:41

1 Answers1

0

The host is the host machine that you run docker on. There is no host in the container. The host runs the container(s), i.e. the containers run on the host.

The ports are HOST:CONTAINER.

Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91