Skip to content

Instantly share code, notes, and snippets.

@mavenugo
Created October 9, 2016 02:32
Show Gist options
  • Save mavenugo/94548915487547a9c69d04859a27dc5a to your computer and use it in GitHub Desktop.
Save mavenugo/94548915487547a9c69d04859a27dc5a to your computer and use it in GitHub Desktop.
madhu@Madhus-MBP ~ $ docker network create --subnet=40.1.1.0/24 my-user-net
68f40c6cd46aae2fd5388b03020e75741ebba6eeca04251068a2b9d509df2e9f
madhu@Madhus-MBP ~ $ docker run --name=my-svc1 --ip=40.1.1.2 --net=usernet -itd busybox sh
e2102faca296b413587c81185140b96a6125191031fa1256163f3bfa2a1da139
docker: Error response from daemon: Invalid address 40.1.1.2: It does not belong to any of this network's subnets.
madhu@Madhus-MBP ~ $
madhu@Madhus-MBP ~ $ docker run --name=my-svc1 --ip=40.1.1.2 --net=my-user-net -itd busybox sh
docker: Error response from daemon: Conflict. The name "/my-svc1" is already in use by container e2102faca296b413587c81185140b96a6125191031fa1256163f3bfa2a1da139. You have to remove (or rename) that container to be able to reuse that name..
See 'docker run --help'.
madhu@Madhus-MBP ~ $ docker run --name=my-svc1 --ip=40.1.1.2 --net=my-user-net -itd busybox sh
madhu@Madhus-MBP ~ $ docker rm my-svc1
my-svc1
madhu@Madhus-MBP ~ $ docker run --name=my-svc1 --ip=40.1.1.2 --net=my-user-net -itd busybox sh
072b141a23caf54af5e6091a8eda847787e61eb209d207246d1c7c7bebf4096c
madhu@Madhus-MBP ~ $ docker run --name=my-svc2 --ip=40.1.1.3 my-svc1:mysvc --net=my-user-net -itd busybox sh
Unable to find image 'my-svc1:mysvc' locally
^C
madhu@Madhus-MBP ~ $ docker run --name=my-svc2 --ip=40.1.1.3 --link=my-svc1:mysvc --net=my-user-net -itd busybox sh
84093ed474d985091698db550d9b503c8ac65c7742c7056951e0c21deba3c66c
madhu@Madhus-MBP ~ $ docker exec -it my-svc2 sh
/ # ping mysvc
PING mysvc (40.1.1.2): 56 data bytes
64 bytes from 40.1.1.2: seq=0 ttl=64 time=0.114 ms
64 bytes from 40.1.1.2: seq=1 ttl=64 time=0.093 ms
64 bytes from 40.1.1.2: seq=2 ttl=64 time=0.094 ms
^C
--- mysvc ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.093/0.100/0.114 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment