1

I have read other questions like this and this, but did not got my answer.

I ran this:

docker run -dp 192.168.43.80:80:80 nginx:beta-1

But I got this error:

docker: Error response from daemon: driver failed programming external connectivity on endpoint hardcore_babbage (aa327aefe662c502bbc79d01660c166198f9a08ad588cd946a794e02b0b07dc4): Error starting userland proxy: listen tcp4 192.168.43.86:80: bind: cannot assign requested address.

And I searched for this error but got nothing.

ip a:

2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:2d:eb:7f brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.85/24 brd 192.168.43.255 scope global dynamic enp0s3
       valid_lft 3060sec preferred_lft 3060sec

I use Oracle VirtualBox with three Linux VMs, and all of them has IP 192.168.43.0/24.

I want to run a container that would be accessible via another IP like 192.168.43.80 from the VM which enp0s3's IP is 192.168.43.85. Both with docker run command and docker-compose.

What should I do in this case?

A.L
  • 10,259
  • 10
  • 67
  • 98
Saeed
  • 3,255
  • 4
  • 17
  • 36
  • 2
    Are you missing a second colon; `-p 192.168.43.85:80:80`? Do you need the explicit IP address binding, or is letting the container be visible on all of the VM's interfaces okay (just `-p 80:80`)? – David Maze Jun 24 '21 at 09:49
  • @DavidMaze that was a typo when writing question. I just want one container be accessible via a different public IP. container_a be accessible via 1.1.1.1, container_b via 2.2.2.2, etc. But if I did not specify, all of them be accessible via server main IP, like 192.168.43.85. I hope that was clear – Saeed Jun 24 '21 at 10:07
  • 1
    You have three different IP addresses in the question. Which one is the current VM's address? Without Docker, how do you assign IP addresses to specific processes? – David Maze Jun 24 '21 at 10:15
  • @DavidMaze The current one's IP is `192.168.43.85`. Regarding how I assign specific IP to specific process, I don't know how to do that. – Saeed Jun 24 '21 at 10:41

2 Answers2

0

I did this to solve:

  1. I shut down my VM and enabled the second network interface.
  2. Ran VM and ran ip a to confirm the number one and see new name
  3. Ran ifconfig enp0s8 192.168.43.80 netmask 255.255.255.255 up
  4. Ran docker container docker run -dp192.168.43.80:80:80 nginx:beta-1
Saeed
  • 3,255
  • 4
  • 17
  • 36
0

Since you do not have added any other IP Address, you should do that:

  1. Power off your VM. Enable a new network interface.
  2. Run VM again and type ip a to see the new network interface name
  3. Run ifconfig NETWORK_INTERFACE 192.168.43.80 netmask 255.255.255.0 up
  4. Ping 192.168.43.80 and you should get result.
  5. Now run your docker container via docker run -dp192.168.43.80:80:80 nginx
  6. You should see nginx default web page or any other configured page when you type 192.168.43.80 on your internet browser