狼狼 发表于 2018-5-28 11:00:57

63 docker(2)

  01docker网络模型详解
  

  1、容器的网络模型
  (1)closed container
  # docker run -it --name test --rm --net none busybox:latest /bin/sh
  / # ifconfig -a
  lo      Link encap:Local Loopback
  inet addr:127.0.0.1Mask:255.0.0.0
  inet6 addr: ::1/128 Scope:Host
  UP LOOPBACK RUNNINGMTU:65536Metric:1
  RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:0 (0.0 B)TX bytes:0 (0.0 B)
  #仅有lo接口,没有其他网络接口
  

  (2)bridged container
  # docker run -it --rm --name test busybox:latest /bin/sh
  / # ifconfig
  eth0      Link encap:EthernetHWaddr 02:42:AC:11:00:02
  inet addr:172.17.0.2Bcast:0.0.0.0Mask:255.255.0.0
  inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link
  UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
  RX packets:8 errors:0 dropped:0 overruns:0 frame:0
  TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:648 (648.0 B)TX bytes:648 (648.0 B)
  

  lo      Link encap:Local Loopback
  inet addr:127.0.0.1Mask:255.0.0.0
  inet6 addr: ::1/128 Scope:Host
  UP LOOPBACK RUNNINGMTU:65536Metric:1
  RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:0 (0.0 B)TX bytes:0 (0.0 B)
  

  #启动时设定主机名
  # docker run -it --rm --name test -h myhost.magedu.com busybox:latest /bin/sh
  / # hostname
  myhost.magedu.com
  

  #启动时设定DNS
  # docker run -it --rm --name test -h myhost.magedu.com --dns 172.16.0.1 busybox:latest /bin/sh
  / # nslookup docker.com
  Server:    172.16.0.1
  Address 1: 172.16.0.1
  

  nslookup: can't resolve 'docker.com'
  / # cat /etc/resolv.conf
  nameserver 172.16.0.1
  

  #启动时在hosts中设定域名解决
  # docker run -it --rm --name test -h myhost.magedu.com --dns 172.16.0.1 --add-host "docker.com:172.16.100.1" busybox:latest /bin/sh
  / # nslookup docker.com
  Server:    172.16.0.1
  Address 1: 172.16.0.1
  

  Name:      docker.com
  Address 1: 172.16.100.1 docker.com
  / # 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
  172.16.100.1    docker.com
  172.17.0.2      myhost.magedu.com myhost
  

  #docker0 NAT桥模型上的容器发布给外部网络访问
  #把docker容器的80端口映射至主机上的某随机端口(从32768端口开始)
  # docker run -it --rm -p 80 --net bridge --name web busybox:latest /bin/sh
  # docker port web
  80/tcp -> 0.0.0.0:32768
  # ss -tnl
  State       Recv-Q Send-Q Local Address:Port               Peer Address:Port            
  LISTEN      0      5      192.168.122.1:53                        *:*                  
  LISTEN      0      128         *:22                        *:*                  
  LISTEN      0      128    127.0.0.1:631                     *:*                  
  LISTEN      0      100    127.0.0.1:25                        *:*                  
  LISTEN      0      128          :::22                     :::*                  
  LISTEN      0      128         ::1:631                      :::*                  
  LISTEN      0      100         ::1:25                     :::*                  
  LISTEN      0      128          :::32768                  :::*               
  / # mkdir -p /web/html
  / # vi /web/html/index.html
  <h1>From Web Container</h1>
  / # httpd -f -v -h /web/html/
  宿主机访问
  http://192.168.1.131:32768
  

  # iptables -t nat -vnL
  Chain PREROUTING (policy ACCEPT 64 packets, 5989 bytes)
   pkts bytes target   prot opt in   out   source               destination         
     654596 DOCKER   all--*      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type LOCAL
  

  Chain INPUT (policy ACCEPT 63 packets, 5760 bytes)
   pkts bytes target   prot opt in   out   source               destination         
  

  Chain OUTPUT (policy ACCEPT 91 packets, 5686 bytes)
   pkts bytes target   prot opt in   out   source               destination         
  3   180 DOCKER   all--*      *       0.0.0.0/0         !127.0.0.0/8          ADDRTYPE match dst-type LOCAL
  

  Chain POSTROUTING (policy ACCEPT 98 packets, 6074 bytes)
   pkts bytes target   prot opt in   out   source               destination         
     895619 MASQUERADEall--*      !docker0172.17.0.0/16      0.0.0.0/0         
  0   0 MASQUERADEtcp--*      *       172.17.0.3         172.17.0.3         tcp dpt:80
  

  Chain DOCKER (2 references)
   pkts bytes target   prot opt in   out   source               destination         
  0   0 RETURN   all--docker0 *       0.0.0.0/0            0.0.0.0/0         
  7   388 DNAT       tcp--!docker0 *       0.0.0.0/0            0.0.0.0/0            tcp dpt:32768 to:172.17.0.3:80
  #在POSTROUTING和DOCKER中各添加一条规则,一旦容器被删除,添加的规则自动被删除
  

  #将主机的80端口映射至容器的80端口
  # docker run -it --rm -p 80:80 --net bridge --name web busybox:latest /bin/sh
  # docker port web
  80/tcp -> 0.0.0.0:80
  

  #发布所有端口,指明要公开的端口为80,8080,443
  # docker run -it --rm -P--expose 80 --expose 8080 --expose 443 --net bridge --name web busybox:latest /bin/sh
  # docker port web
  80/tcp -> 0.0.0.0:32771
  8080/tcp -> 0.0.0.0:32769
  443/tcp -> 0.0.0.0:32770
  # docker ps
  CONTAINER ID      IMAGE               COMMAND             CREATED            STATUS            PORTS                                                                  NAMES
  7cf269b12b50      busybox:latest      "/bin/sh"         About a minute ago   Up About a minute   0.0.0.0:32771->80/tcp, 0.0.0.0:32770->443/tcp, 0.0.0.0:32769->8080/tcp   web
  
  (3) 联盟式容器
  启动一个容器joind_web,让其使用已经存在的容器web的网络名称空间
  

  #跟已存在的web容器的IP地址一样
  # docker run --rm --name joided_web --net container:web busybox:latest ifconfig -aeth0      Link encap:EthernetHWaddr 02:42:AC:11:00:02
  inet addr:172.17.0.2Bcast:0.0.0.0Mask:255.255.0.0
  inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link
  UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
  RX packets:8 errors:0 dropped:0 overruns:0 frame:0
  TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:648 (648.0 B)TX bytes:648 (648.0 B)
  

  lo      Link encap:Local Loopback
  inet addr:127.0.0.1Mask:255.0.0.0
  inet6 addr: ::1/128 Scope:Host
  UP LOOPBACK RUNNINGMTU:65536Metric:1
  RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:0 (0.0 B)TX bytes:0 (0.0 B)
  / # ifconfig
  eth0      Link encap:EthernetHWaddr 02:42:AC:11:00:02
  inet addr:172.17.0.2Bcast:0.0.0.0Mask:255.255.0.0
  inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link
  UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
  RX packets:12 errors:0 dropped:0 overruns:0 frame:0
  TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:1066 (1.0 KiB)TX bytes:996 (996.0 B)
  

  lo      Link encap:Local Loopback
  inet addr:127.0.0.1Mask:255.0.0.0
  inet6 addr: ::1/128 Scope:Host
  UP LOOPBACK RUNNINGMTU:65536Metric:1
  RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:0 (0.0 B)TX bytes:0 (0.0 B)
  
  

  #跟已存在的web容器监听的端口一样
  / # httpd
  / # netstat -tan
  Active Internet connections (servers and established)
  Proto Recv-Q Send-Q Local Address         Foreign Address         State      
  tcp      0      0 :::80                   :::*                  LISTEN   
  # docker run --rm --name joided_web --net container:web busybox:latest netstat -tan
  Active Internet connections (servers and established)
  Proto Recv-Q Send-Q Local Address         Foreign Address         State      
  tcp      0      0 :::80                   :::*                  LISTEN
  

  #容器使用宿主机的网络地址
  # docker run -it --rm--net host --name web busybox:latest /bin/sh
  / # ifconfig
  docker0   Link encap:EthernetHWaddr 02:42:F5:88:C0:2F
  inet addr:172.17.0.1Bcast:0.0.0.0Mask:255.255.0.0
  inet6 addr: fe80::42:f5ff:fe88:c02f/64 Scope:Link
  UP BROADCAST MULTICASTMTU:1500Metric:1
  RX packets:2698 errors:0 dropped:0 overruns:0 frame:0
  TX packets:3447 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:156234 (152.5 KiB)TX bytes:10177850 (9.7 MiB)
  

  eno16777736 Link encap:EthernetHWaddr 00:0C:29:50:27:C4
  inet addr:192.168.1.131Bcast:192.168.1.255Mask:255.255.255.0
  inet6 addr: fe80::20c:29ff:fe50:27c4/64 Scope:Link
  UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
  RX packets:679372 errors:0 dropped:6 overruns:0 frame:0
  TX packets:247168 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:1000
  RX bytes:375438208 (358.0 MiB)TX bytes:46560004 (44.4 MiB)
  

  lo      Link encap:Local Loopback
  inet addr:127.0.0.1Mask:255.0.0.0
  inet6 addr: ::1/128 Scope:Host
  UP LOOPBACK RUNNINGMTU:65536Metric:1
  RX packets:6951 errors:0 dropped:0 overruns:0 frame:0
  TX packets:6951 errors:0 dropped:0 overruns:0 carrier:0
  collisions:0 txqueuelen:0
  RX bytes:21397144 (20.4 MiB)TX bytes:21397144 (20.4 MiB)
  
  # docker run -it --rm--net host --name web centos:latest /bin/bash
  # yum-y install iproute
  # ip addr list
  1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  inet 127.0.0.1/8 scope host lo
     valid_lft forever preferred_lft forever
  inet6 ::1/128 scope host
     valid_lft forever preferred_lft forever
  2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  link/ether 00:0c:29:50:27:c4 brd ff:ff:ff:ff:ff:ff
  inet 192.168.1.131/24 brd 192.168.1.255 scope global eno16777736
     valid_lft forever preferred_lft forever
  inet6 fe80::20c:29ff:fe50:27c4/64 scope link
     valid_lft forever preferred_lft forever
  3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
  link/ether 02:42:f5:88:c0:2f brd ff:ff:ff:ff:ff:ff
  inet 172.17.0.1/16 scope global docker0
     valid_lft forever preferred_lft forever
  inet6 fe80::42:f5ff:fe88:c02f/64 scope link
     valid_lft forever preferred_lft forever
  # yum -y install httpd
  

  # docker run --name web --net bridge busybox:latest httpd
  # docker ps -a
  CONTAINER ID      IMAGE               COMMAND             CREATED            STATUS                        PORTS               NAMES
  9f9591b73bb2      busybox:latest      "httpd"             About a minute ago   Exited (0) About a minute ago                     web
  # docker rm web
  web
  # docker run --name web --net bridge busybox:latest httpd -f
  # docker ps
  CONTAINER ID      IMAGE               COMMAND             CREATED             STATUS            PORTS               NAMES
  ca8b05d52a28      busybox:latest      "httpd -f"          47 seconds ago      Up 45 seconds                           web
  # docker kill web
  web
  # docker rm web
  web
  

  #让docker容器在后台运行
  # dockerrun -d --name web --net bridge -p 80:80 busybox:latest httpd -f
  c9455d2691b7b72689893119d257937c74242c325b4c3d4f2bdb099cbee6700f
  # docker ps
  CONTAINER ID      IMAGE               COMMAND             CREATED             STATUS            PORTS                NAMES
  c9455d2691b7      busybox:latest      "httpd -f"          50 seconds ago      Up 48 seconds       0.0.0.0:80->80/tcp   web
  
  inspect命令:
  #查看IP地址
  # docker inspect -f ``.`NetworkSettings`.`IPAddress` web
  172.17.0.2
  #查看进程号
  # docker inspect -f ``.`State`.`Pid` web                        
  62887
  

  # docker top web
  UID               PID               PPID                C                   STIME               TTY               TIME                CMD
  root                62887               18715               0                   21:27               ?                   00:00:00            httpd -f
  

  02dockerfile详解
  

  # vim test.dockerfile
  # Mage Edu
  FROM busybox:latest
  MAINTAINER MageEdu <mage@magedu.com>
  COPY index.html /web/html/index.html
  

  EXPOSE 80/tcp
  

  CMD ["httpd", "-f", "-h", "/web/html"]
  

  # vim index.html
  <h1>From Docker Container(Dockerfile)</h1>
  # mkdir docker
  # mv index.html docker/
  # mv test.dockerfile docker/
  # docker build -f docker/test.dockerfile docker/
  Sending build context to Docker daemon 3.072 kB
  Step 1 : FROM busybox:latest
   ---> 7968321274dc
  Step 2 : MAINTAINER MageEdu <mage@magedu.com>
   ---> Running in f3d1afc8cab3
   ---> ad76be7eb604
  Removing intermediate container f3d1afc8cab3
  Step 3 : COPY index.html /web/html/index.html
   ---> 8b38e8071ddd
  Removing intermediate container b788fa3a1c94
  Step 4 : CMD httpd -f -h /web/html
   ---> Running in a2b6a483f15b
   ---> 2cde4a22e191
  Removing intermediate container a2b6a483f15b
  Successfully built 2cde4a22e191
  # docker images
  REPOSITORY                   TAG               IMAGE ID            CREATED             SIZE
  <none>                     <none>            2cde4a22e191      4 minutes ago       1.11 MB
  centos                     newuser             4b761c9a987a      6 days ago          192.1 MB
  192.168.1.132:5000/busybox   1.2.1               7968321274dc      2 weeks ago         1.11 MB
  docker.io/busybox            latest            7968321274dc      2 weeks ago         1.11 MB
  docker.io/centos             latest            67591570dd29      6 weeks ago         191.8 MB
  

  # docker build -f docker/test.dockerfile -t busybox:webserver docker/
  Sending build context to Docker daemon 3.072 kB
  Step 1 : FROM busybox:latest
   ---> 7968321274dc
  Step 2 : MAINTAINER MageEdu <mage@magedu.com>
   ---> Using cache
   ---> ad76be7eb604
  Step 3 : COPY index.html /web/html/index.html
   ---> Using cache
   ---> 8b38e8071ddd
  Step 4 : CMD httpd -f -h /web/html
   ---> Using cache
   ---> 2cde4a22e191
  Successfully built 2cde4a22e191
  

  # docker images
  REPOSITORY                   TAG               IMAGE ID            CREATED             SIZE
  busybox                      webserver         2cde4a22e191      7 minutes ago       1.11 MB
  centos                     newuser             4b761c9a987a      6 days ago          192.1 MB
  192.168.1.132:5000/busybox   1.2.1               7968321274dc      2 weeks ago         1.11 MB
  docker.io/busybox            latest            7968321274dc      2 weeks ago         1.11 MB
  docker.io/centos             latest            67591570dd29      6 weeks ago         191.8 MB
  

  # docker build -f docker/test.dockerfile -t busybox:web2 docker/
  Sending build context to Docker daemon 3.072 kB
  Step 1 : FROM busybox:latest
   ---> 7968321274dc
  Step 2 : MAINTAINER MageEdu <mage@magedu.com>
   ---> Using cache
   ---> ad76be7eb604
  Step 3 : COPY index.html /web/html/index.html
   ---> Using cache
   ---> 8b38e8071ddd
  Step 4 : EXPOSE 80/tcp
   ---> Running in caad20a45dd8
   ---> 95351c4c60d3
  Removing intermediate container caad20a45dd8
  Step 5 : CMD httpd -f -h /web/html
   ---> Running in 3b6066935b57
   ---> ec5bd0d26b61
  Removing intermediate container 3b6066935b57
  Successfully built ec5bd0d26b61
  # docker images
  REPOSITORY                   TAG               IMAGE ID            CREATED             SIZE
  busybox                      web2                ec5bd0d26b61      7 seconds ago       1.11 MB
  busybox                      webserver         2cde4a22e191      10 minutes ago      1.11 MB
  centos                     newuser             4b761c9a987a      6 days ago          192.1 MB
  192.168.1.132:5000/busybox   1.2.1               7968321274dc      2 weeks ago         1.11 MB
  docker.io/busybox            latest            7968321274dc      2 weeks ago         1.11 MB
  docker.io/centos             latest            67591570dd29      6 weeks ago         191.8 MB
  

  # docker ps
  CONTAINER ID      IMAGE               COMMAND             CREATED             STATUS            PORTS                NAMES
  c9455d2691b7      busybox:latest      "httpd -f"          2 days ago          Up 2 days         0.0.0.0:80->80/tcp   web
  # docker kill web
  web
  # docker rm web
  web
  

  # docker run -d busybox:web2
  d57228046a3d1261a80de72f528a5b01a322961bfd8be867da13f276c95f3a3a
  

  # docker ps
  CONTAINER ID      IMAGE               COMMAND                  CREATED            STATUS            PORTS               NAMES
  d57228046a3d      busybox:web2      "httpd -f -h /web/htm"   About a minute ago   Up About a minute   80/tcp            focused_goodall
  

  # docker port d57228046a3d
  # docker kill d57228046a3d
  d57228046a3d
  

  # docker run -d --name web -P busybox:web2
  4e0f3885a830d94decdbf2789266de7fb8a507659245854daf124799ce05e028
  

  # docker port web
  80/tcp -> 0.0.0.0:32772
  

  http://192.168.1.131:32772
  

  测试成功
  

  

  03dockerfile详解
  # mkdir docker-httpd
  # cd docker-httpd/
  FROM centos:latest
  MAINTAINER MageEdu "<mage@magedu.com>"
  

  RUN sed -i -e 's@^mirrorlist.*repo=os.*$@baseurl=http://172.16.0.1/cobbler/ks_mirror/$releaserver/@g' -e '/^mirrorlist.*repo=updates/a enabled=0' -e
  '/^mirrorlist.*repo=extras/a enabled=0' /etc/yum.repos.d/CentOS-Base.repo && \
      yum -y install httpd php php-mysql php-mbstring && \
      yum clean all && \
      echo -e '<?php\n\tphpinfo();\n?>' > /var/www/html/info.php
  

  EXPOSE 80/tcp
  

  CMD ["/usr/sbin/httpd","-f","/etc/httpd/conf/httpd.conf","-DFOREGROUND"]
  # docker build -f httpd.df -t httpd:2.4 ./
  Sending build context to Docker daemon 2.048 kB
  Step 1 : FROM centos:latest
   ---> 67591570dd29
  Step 2 : MAINTAINER MageEdu "<mage@magedu.com>"
   ---> Using cache
   ---> f6eacba2a721
  Step 3 : RUN yum -y install httpd php php-mysql php-mbstring &&         yum clean all &&   echo -e '<?php\n\tphpinfo();\n?>' > /var/www/html/info.php
   ---> Using cache
   ---> f1a8a2a4ee60
  Step 4 : EXPOSE 80/tcp
   ---> Running in fe4b765dcbfd
   ---> c02172ed48ed
  Removing intermediate container fe4b765dcbfd
  Step 5 : CMD /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -DFOREGROUND
   ---> Running in 2a073274d5d3
   ---> 8fe09a670fb9
  Removing intermediate container 2a073274d5d3
  Successfully built 8fe09a670fb9
  

  # docker images
  REPOSITORY                   TAG               IMAGE ID            CREATED             SIZE
  httpd                        2.4               8fe09a670fb9      3 minutes ago       266.7 MB
  busybox                      web2                ec5bd0d26b61      About an hour ago   1.11 MB
  busybox                      webserver         2cde4a22e191      About an hour ago   1.11 MB
  centos                     newuser             4b761c9a987a      6 days ago          192.1 MB
  192.168.1.132:5000/busybox   1.2.1               7968321274dc      2 weeks ago         1.11 MB
  docker.io/busybox            latest            7968321274dc      2 weeks ago         1.11 MB
  

  # docker run --rm --name httpd -P httpd:2.4
  # docker port httpd
  80/tcp -> 0.0.0.0:32774
  # docker kill httpd
  # docker run -d --name httpd -p 80:80 httpd:2.4
  # docker ps
  CONTAINER ID      IMAGE               COMMAND                  CREATED             STATUS            PORTS                NAMES
  2e0a3ba92f18      httpd:2.4         "/usr/sbin/httpd -f /"   40 seconds ago      Up 38 seconds       0.0.0.0:80->80/tcp   httpd
  2e0a3ba92f18674b848924eaa40ab66cbd1a66669847526e366f2af4dda0872d
  

  # docker ps
  CONTAINER ID      IMAGE               COMMAND                  CREATED             STATUS            PORTS                NAMES
  2e0a3ba92f18      httpd:2.4         "/usr/sbin/httpd -f /"   7 minutes ago       Up 7 minutes      0.0.0.0:80->80/tcp   httpd
  # docker stop httpd
  httpd
  

  # docker rm httpd
  httpd
  

  # vim httpd.df
  FROM centos:latest
  MAINTAINER MageEdu "<mage@magedu.com>"
  

  RUN yum -y install httpd php php-mysql php-mbstring && \
      yum clean all && \
      echo -e '<?php\n\tphpinfo();\n?>' > /var/www/html/info.php
  

  VOLUME /var/www/html
  EXPOSE 80/tcp
  

  CMD ["/usr/sbin/httpd","-f","/etc/httpd/conf/httpd.conf","-DFOREGROUND"]
  # docker build -f httpd.df -t httpd:0.1 ./
  Sending build context to Docker daemon 2.048 kB
  Step 1 : FROM centos:latest
   ---> 67591570dd29
  Step 2 : MAINTAINER MageEdu "<mage@magedu.com>"
   ---> Using cache
   ---> f6eacba2a721
  Step 3 : RUN yum -y install httpd php php-mysql php-mbstring &&         yum clean all &&      echo -e '<?php\n\tphpinfo();\n?>' > /var/www/html/info.php
   ---> Using cache
   ---> f1a8a2a4ee60
  Step 4 : VOLUME /var/www/html
   ---> Running in 58ab7b732b00
   ---> a1dfec50fa16
  Removing intermediate container 58ab7b732b00
  Step 5 : EXPOSE 80/tcp
   ---> Running in 58d20c2ee361
   ---> 0142accd29d8
  Removing intermediate container 58d20c2ee361
  Step 6 : CMD /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -DFOREGROUND
   ---> Running in 6772c7d6154f
   ---> 97b1901c5b98
  Removing intermediate container 6772c7d6154f
  Successfully built 97b1901c5b98
  # docker run -it --rm --name httpd -p 80:80 httpd:0.1 /bin/bash
  # ls /var/www/html/
  info.php
  # ls /var/lib/docker/volumes/
  1adb8a2119488a4b9517e6890a4f89759bc0ad6fc9933227c445ea899d5327e1
  bf2b562a3277475a3695468352f2f944c75ca7ee2433be6d27294f3e1e332757
  # ls /var/lib/docker/volumes/1adb8a2119488a4b9517e6890a4f89759bc0ad6fc9933227c445ea899d5327e1/_data/
  info.php
  # cat /var/lib/docker/volumes/1adb8a2119488a4b9517e6890a4f89759bc0ad6fc9933227c445ea899d5327e1/_data/info.php
  <?php
        phpinfo();
  ?>
  # docker stop httpd
  httpd
  # mkdir -p /web/html
  # unzip phpMyAdmin-4.0.5-all-languages.zip
  # mv phpMyAdmin-4.0.5-all-languages /web/html/pma
  # docker run -it --rm --name httpd -p 80:80 -v /web/html/:/var/www/html httpd:0.1 /bin/bash
  # ls /var/www/html/
  pma
  # yum -y install mariadb-server
  # vim /etc/my.cnf
  添加
  skip_name_resolve = on
  innodb_file_per_table = on
  # systemctl start mariadb.service
  # docker run -it --rm --name httpd -p 80:80 -v /web/html/:/var/www/html httpd:0.1 /bin/bash
  # yum install iproute -y
  # ip addr list
  1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
      inet 127.0.0.1/8 scope host lo
         valid_lft forever preferred_lft forever
      inet6 ::1/128 scope host
         valid_lft forever preferred_lft forever
  80: eth0@if81: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
      link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
      inet 172.17.0.2/16 scope global eth0
         valid_lft forever preferred_lft forever
      inet6 fe80::42:acff:fe11:2/64 scope link
         valid_lft forever preferred_lft forever
  # exit
  MariaDB [(none)]> GRANT ALL ON *.* TO 'root'@'172.%.%.%' IDENTIFIED BY 'mageedu';
  MariaDB [(none)]> GRANT ALL ON *.* TO 'root'@'172.168.1.%' IDENTIFIED BY 'mageedu';   
  MariaDB [(none)]> FLUSH PRIVILEGES;
  MariaDB [(none)]> \q
  # docker run -it --rm --name httpd -p 80:80 -v /web/html/:/var/www/html httpd:0.1
  http://192.168.1.131/pma/index.php
  # openssl rand -base64 20
  8kl6zMcqb40pPlBmE0VrjezrVlM=
  

  # cd /web/html/pma/
  # cp config.sample.inc.php config.inc.php
  # vim config.inc.php
  修改
  $cfg['blowfish_secret'] = 'a8b7c6d';
  为
  $cfg['blowfish_secret'] = '8kl6zMcqb40pPlBmE0VrjezrVlM=';
  修改
  $cfg['Servers'][$i]['host'] = 'localhost';
  为
  $cfg['Servers'][$i]['host'] = '192.168.1.131';
  
     
  
页: [1]
查看完整版本: 63 docker(2)