httpd 連線

  1. 使用 centos/httpd image 建立名為 web 的容器,讓 host 80 port 連到容器的 httpd 8080 port。
    [root@dyw219 ~]# docker run -dit --name web -p 8080:80 centos/httpd
    ed1f252bbd4e6b7c8053162cbcfbcf2d50ce4dfffd02e4a2b0d900ae89a9a401
    
  2. docker ps 查看執行程序。
    [root@dyw219 ~]# docker ps
    CONTAINER ID  IMAGE        COMMAND         CREATED    STATUS       PORTS                 NAMES
    ed1f252bbd4e  centos/httpd "/run-httpd.sh" 7 seconds  Up 6 seconds 0.0.0.0:8080->80/tcp  web
    
  3. 使用 curl 連線 host 的 8080 port,出現 CentOS 歡迎網頁。
    [root@dyw219 ~]# curl -sN http://0.0.0.0:8080/ | grep 'CentOS Project'
                <p class="lead">The CentOS Project has nothing to do with 
    this website or its content,
                Unless you intended to visit CentOS.org, the CentOS Project 
    does not have anything to do with this website,
                <h2>The CentOS Project</h2>
    
  4. docker stop 關閉網頁。
    [root@dyw219 ~]# docker stop ed1f252bbd4e
    
  5. docker ps 查看已無運行的程序。
    [root@dyw219 ~]# docker ps
    CONTAINER ID   IMAGE    COMMAND  CREATED   STATUS   PORTS     NAMES
    [root@dyw219 ~]#
    
  6. docker ps -a 查看,該程序狀態是 Exited,隨時可以啟動。
    [root@dyw219 ~]# docker ps -a | grep 'centos/httpd'
    ed1f252bbd4e centos/httpd  "/run-httpd.sh"  9 minutes ago  Exited (137) ... web