forked from Sonal0409/DevOps_ClassNotes
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerNetworking
More file actions
56 lines (42 loc) · 1.54 KB
/
DockerNetworking
File metadata and controls
56 lines (42 loc) · 1.54 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
To set custome IP address range to your container in docker
sudo vim /etc/default/docker
add this line to file
DOCKER_OPTS="--bip=10.66.33.10/24"
then reboot
after reboot start a container
docker run -it --name t2 jangorecki/r-base-dev /bin/bash
and check ip of a container
docker inspect --format '{{ .NetworkSettings.IPAddress }}' t2
OR
docker exec -it c1 bash -c "echo -e 'IPADDR=172.17.0.4 \n HOSTNAME=c1' >> /etc/sysconfig/network-scripts/ifcfg-eth0; /etc/init.d/network restart";
OR - to change the IP address of this docker container
You will have to first detach the container from the custom network and the connect it back by providing the ip.
You can follow the following steps :
docker network disconnect [OPTIONS] NETWORK CONTAINER
docker network connect --ip 192.168.150.3 NETWORK CONTAINER
docker network ls
20 docker run -d --name myn1 nginx
21 docker ps -a
22 docker inspect myn1
23 clear
24 docker network create --driver bridge edureka1
25 docker network ls
26 docker network create --driver bridge edureka2
27 docker network ls
28 clear
29 docker run -itd --name b1 --network edureka1 busybox
30 docker inspect b1
31 clear
32 docker run -itd --name b2 --network edureka1 busybox
33 docker inspect b2
34 clear
35 docker attach b1
36 docker run -itd --name b3 --network edureka2 busybox
37 docker inspect b3
38 clear
39 docker attach b3
40 docker attach b2
41 docker network connect edureka2 b2
42 docker inspect b2
43 clear
44 docker attach b2