Skip to content

Instantly share code, notes, and snippets.

@Yasushi
Last active March 28, 2019 00:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yasushi/19cf33347580b3b8f642c4e1812de810 to your computer and use it in GitHub Desktop.
Save Yasushi/19cf33347580b3b8f642c4e1812de810 to your computer and use it in GitHub Desktop.
boot2docker static ip
#!/bin/sh
kill `cat /var/run/udhcpc.eth0.pid`
ifconfig eth0 192.168.0.100 netmask 255.255.255.0 up
ip route add default via 172.168.0.1 dev eth0
echo nameserver 8.8.8.8 >> /etc/resolv.conf
#/mnt/sda1/var/lib/boot2docker/bootlocal.sh
DOCKER_TLS=no
@suresh1566
Copy link

We can set permanet ip address for docker machine in two way:

Option 1:
Start the docker machine then use below command:

[suresh@suresh ~]$ docker-machine start manager1

echo "ifconfig eth1 netmask broadcast " | docker-machine ssh sudo tee /var/lib/boot2docker/bootsync.sh > /dev/null

echo "ifconfig eth1 192.168.99.100 netmask 255.255.255.0 broadcast 192.168.99.255 up" | docker-machine ssh manager1 sudo tee /var/lib/boot2docker/bootsync.sh > /dev/null

Restart docker machine:

[suresh@suresh ~]$ docker-machine stop worker1

[suresh@suresh ~]$ docker-machine start worker1

Veify ip address:
[suresh@suresh ~]$ docker-machine ip worker1
192.168.99.100

Option 2:
Start the docker machine then connect to docker machine and make the following changes:

[suresh@suresh ~]$ docker-machine start worker1

[suresh@suresh ~]$ docker-machine ssh worker1

Create the bootsync.sh file and make following changes:
docker@worker1:~$ sudo vi /var/lib/boot2docker/bootsync.sh
ifconfig eth1 192.168.99.101 netmask 255.255.255.0 broadcast 192.168.99.255 up

[suresh@suresh ~]$ docker-machine stop worker1

[suresh@suresh ~]$ docker-machine start worker1

Veify ip address:
[suresh@suresh ~]$ docker-machine ip worker1
192.168.99.101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment