Change docker machine ip address on virtualbox

Change docker machine ip address on virtualbox

Mar 22, 2022 4:00 PM (a month ago)

The default docker machine ip range in and this ip most of the times isn't available on your network for other devices.

Changing Docker machine is tricky and can cause a lot of problems. Here's the summery of hours and hours of debugging.

# My Goal

  • ✅ Change docker machine ip to
  • ✅ Make docker machine available to the devices on the network.

# Things to check before proceeding

  • ✅ Check that the ip you want is available on the network and not assigned to another device.
  • ✅ Docker toolbox is installed
  • ✅ Default machine is created on virtualbox and working correctly

# Step 1: Make ip static for the Host-only adapter

  • Open VirtualBox -> file -> Host Network Manager

step 1

  • Change on of the Host-only adapter VirtualBox Host-Only Eithernet #2 to your the ip in this case
  • Disable DHCP SERVER for all VirtualBox adapters it's not good for docker!

step 2

# Step 2: Assign Default machine to the correct adapter

step 3

If you want this machine to have access to the internet assign adapter 1 as Bridged Adapter

step 4

# Step 3: Enable Adapter as NAT to use port-farwarding

Warning this step is too manual! You need to list all port you'll be using in that docker machine.

Here I'm using ports 80, 433, and 6001 for websockets. What matters here is ssh port that docker uses on your machine to connect to the docker instance in the virtual machine. you can find this port by execting the following command and the copy the output ip and port.

docker ps

# Step 4: Inform Docker with the new ip

Boot2docker will look for a file called when booting, we'll use this file to execute this command on the virtual machine directly:

echo "kill \$(cat /var/run/; kill \$(cat /var/run/; ifconfig eth1 netmask broadcast up" | sudo tee /var/lib/boot2docker/ > /dev/null

# Some explanation for the command above ☝

  • kill cat /var/run/ Kill the DHCP server for the adapter 1 (bridged connection)
  • kill cat /var/run/ Kill the DHCP server for the adapter 2 (Host Only Adapter)
  • ifconfig eth1 netmask broadcast up force eth1 (the host only adapter) to assigned the ip Please note here that you need to replace the ip with the ip you want!

step 6

# Step 5: Restart the virtual machine

Use the comments bellow 👇 to ask me anything. I'll answer all of your questions.

My Newsletter

I send out an email every so often about cool stuff I'm working on or launching. If you dig, go ahead and sign up!

No spam, only goldden nuggets 💎


Ahmed Nagi - Powerd By Vuepress . Hosted with GitHub and Netlify .