How to Set a Static IP Address in Boot2Docker: A Complete Step-by-Step Guide

Website Visitors:
Contents

Configuring a static IP address on your Boot2Docker virtual machine (VM) is critical when you need predictable network access for development, testing, or integration with other services. Boot2Docker, once the default Docker VM solution for non-native environments, runs on TinyCore Linux and offers a simple startup script mechanism that can automate network settings—including static IP assignment—at every boot.

In this guide, I’ll show you how to overwrite DHCP and set a fixed IP address on your Boot2Docker VM’s primary network adapter (usually eth0). We’ll use Boot2Docker’s powerful /var/lib/boot2docker/bootsync.sh startup script, ensure it’s executable, and reboot to apply the changes.

  • You have a Boot2Docker VM running (via VirtualBox, VMware, or similar).
  • You can SSH into the Boot2Docker VM.
  • You have root privileges inside the VM (most Boot2Docker sessions start with root access).

Login to Boot2Docker VM and list network interfaces with:

1
ip addr

Look for the main adapter, typically named eth0, which will have a hardware MAC address and your current IP (usually assigned via DHCP).


Boot2Docker executes /var/lib/boot2docker/bootsync.sh at every boot, before the Docker daemon starts. We’ll use this script to kill the DHCP client and assign a static IP.

Run below command to create bootsync.sh file and edit with vi editor:

1
sudo vi /var/lib/boot2docker/bootsync.sh

Paste the following script, replacing the IP, netmask, gateway, and DNS as needed for your environment:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh

# Interface to configure
IFACE="eth0"

# Your desired network settings
IP_ADDR="10.10.1.236"
NETMASK="255.255.255.0"
BROADCAST="10.10.1.255"
GATEWAY="10.10.1.1"
DNS1="8.8.8.8"
DNS2="8.8.4.4"

# Stop DHCP client
if [ -f /var/run/udhcpc.${IFACE}.pid ]; then
  kill "$(cat /var/run/udhcpc.${IFACE}.pid)" 2>/dev/null
fi

# Configure the interface
ifconfig "${IFACE}" "${IP_ADDR}" netmask "${NETMASK}" broadcast "${BROADCAST}" up

# Set default route
ip route replace default via "${GATEWAY}" dev "${IFACE}" 2>/dev/null || route add default gw "${GATEWAY}" dev "${IFACE}"

# Set resolvers
printf "nameserver %s\nnameserver %s\n" "${DNS1}" "${DNS2}" > /etc/resolv.conf

Boot2Docker won’t run your script unless it’s executable. Set permissions with:

1
sudo chmod +x /var/lib/boot2docker/bootsync.sh

Now, to activate your changes, reboot your Boot2Docker VM:

1
sudo reboot

After reboot, SSH back in and check your IP:

1
ip addr

You should see your chosen static IP assigned to eth0. Also, check that DNS resolution works:

1
2
cat /etc/resolv.conf
ping google.com

Place all the commands you want to run automatically after a reboot inside the same bootsync.sh file, using the sudo for each command as needed. Files or folders placed in the /var/lib/boot2docker directory persist and are not deleted after a reboot.


  • Interface name: If your main NIC is not eth0, change the script variable to match (e.g., eth1).
  • Persistent changes: The bootsync.sh script runs on every boot, providing persistent static configuration.
  • Docker containers: This setting affects the VM’s primary IP. For container IPs, use Docker’s bridge/network controls.
  • Updating settings: Edit /var/lib/boot2docker/bootsync.sh, update values, and reboot.
  • DHCP conflict: Disable or adjust DHCP settings in your VM host network (e.g., VirtualBox Host-only Manager) for best results.

With this workflow, Boot2Docker can reliably present the same IP every time, making development and networking much more predictable, especially in complex setups or when interfacing with other hosts or cloud services. The bootsync.sh hack is flexible and can be extended to other boot-time tasks as well!

Your inbox needs more DevOps articles.

Subscribe to get our latest content by email.

Buy Me A Coffee
If you've found my content valuable, please consider buying me a coffee. Thank you!