$ sudo docker network create --subnet 192.168.100.0/24 --gateway 192.168.100.254 alpha
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
11b17a448e68 alpha bridge local
ecac5a21a46c bridge bridge local
$ sudo docker volume create web_vol
$ sudo docker volume create db_vol
$ sudo docker run -d --name web1 -v web_vol:/usr/local/apache2/htdocs:ro --network alpha httpd:latest
$ docker inspect web1
"Mounts": [
{
"Type": "volume",
"Name": "web_vol",
"Source": "/var/lib/docker/volumes/web_vol/_data",
"Destination": "/usr/local/apache2/htdocs",
"Driver": "local",
"Mode": "ro",
"RW": false,
"Propagation": ""
}
],
$ sudo docker run -d --name web2 -v web_vol:/usr/local/apache2/htdocs:ro --network alpha httpd:latest
$ docker inspect web2
"Mounts": [
{
"Type": "volume",
"Name": "web_vol",
"Source": "/var/lib/docker/volumes/web_vol/_data",
"Destination": "/usr/local/apache2/htdocs",
"Driver": "local",
"Mode": "ro",
"RW": false,
"Propagation": ""
}
],
$ sudo docker run -itd --name os -v web_vol:/root/html:rw --network brid4ge centos:latest
$ docker inspect os
"Mounts": [
{
"Type": "volume",
"Name": "web_vol",
"Source": "/var/lib/docker/volumes/web_vol/_data",
"Destination": "/root/html",
"Driver": "local",
"Mode": "rw",
"RW": true,
"Propagation": ""
}
],
$ sudo docker network connect bridge web1
$ sudo docker network connect bridge web2
$ sudo docker run -itd --name db -v db_vol:/var/lib/mysql:rw --network alpha -e 'MYSQL_ROOT_PASSWORD=1234' mysql:5.7
$ sudo docker inspect db // db 볼륨 연결 장소 확인
"Mounts": [
{
"Type": "volume",
"Name": "db_vol",
"Source": "/var/lib/docker/volumes/db_vol/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "rw",
"RW": true,
"Propagation": ""
}
],
$ sudo docker cp web1:/usr/local/apache2/htdocs/index.html .
$ sudo vi index.html
<html><body><h1>Hello Docker!</h1></body></html>
$ sudo docker cp index.html os:/root/html/
$ sudo docker exec web1 cat /usr/local/apache2/htdocs/index.html
<html><body><h1>Hello Docker!</h1></body></html>
$ sudo docker exec web2 cat /usr/local/apache2/htdocs/index.html
<html><body><h1>Hello Docker!</h1></body></html>
$ sudo docker exec web1 cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.100.1 2f61f00878ac
172.17.0.3 2f61f00878ac
$ sudo docker exec web2 cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.100.2 148495bc3aa4
172.17.0.4 148495bc3aa4
$ curl 172.17.0.3
<html><body><h1>Hello Docker!</h1></body></html>
$ curl 172.17.0.4
<html><body><h1>Hello Docker!</h1></body></html>