Asked  7 Months ago    Answers:  5   Viewed   37 times

As the title says. I need to be able to retrieve the IP address the docker hosts and the portmaps from the host to the container, and doing that inside of the container.

 Answers

61
/sbin/ip route|awk '/default/ { print $3 }'

As @MichaelNeale noticed, there is no sense to use this method in Dockerfile (except when we need this IP during build time only), because this IP will be hardcoded during build time.

Tuesday, June 1, 2021
 
diegoiglesias
answered 7 Months ago
65

The docker version is 1.10.1. I want the docker container to have same ip as the host with ports exposed.

When you use --net=host it tells the container to use the hosts networking stack. So you can't expose ports to the host, because it is the host (as far as the network stack is concerned).

docker inspect might not show the expose ports, but if you have an application listening on a port, it will be available as if it were running on the host.

Thursday, July 22, 2021
 
elias
answered 5 Months ago
82

Use Socket::ip_address_list.

Socket.ip_address_list #=> Array of AddrInfo
Monday, August 9, 2021
 
Anders Andersen
answered 4 Months ago
61

You're already exposing the port internally, so the only other thing I can suggest is to check you are opening the port when launching your image too:

docker run -it -p 5000:5000 <imagename>

This will open port 5000 inside the instance to port 5000 on your local machine, and should then be accessible on 127.0.0.1:5000 or localhost:5000.

You should also ensure that you are accepting any host name within Main() in Program.cs with .UseUrls("http://*:5000/") on your WebHostBuilder.

Friday, August 13, 2021
 
Philip Weiser
answered 4 Months ago
33

You need to map a page into the kernel memory as follows:

void * mapping = kmap_atomic(page, KM_USER0);
// work with mapping...
kunmap_atomic(mapping, KM_USER0);

This trick is required as there is a HighMemory concept in Linux (see this link for ex.).

UPD: You can use kmap instead of kmap_atomic in non-atomic contexts.

Monday, October 11, 2021
 
csi
answered 2 Months ago
csi
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share