docker machine으로 Apache 시작

환경


  • MacBookPro
  • Catalina
  • VirtualBox
  • DockerForMac

  • 지금의 상태



    이미 작성된 가상 호스트에서 Docker 호스트의 상태가 비활성 상태입니다.
    %docker-machine ls
    NAME      ACTIVE   DRIVER       STATE     URL   SWARM   DOCKER    ERRORS
    default   -        virtualbox   Stopped                 Unknown   
    

    가상 상자에서 Docker 데몬 시작


    %docker-machine start default
    Starting "default"...
    (default) Check network to re-create if needed...
    (default) Waiting for an IP...
    Machine "default" was started.
    Waiting for SSH to be available...
    Detecting the provisioner...
    Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
    

    가상 상자에서 Docker 데몬 시작 확인


    %docker-machine ls                 
    NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER      ERRORS
    default   *        virtualbox   Running   tcp://192.168.99.100:2376           v19.03.12   
    

    가상 박스의 Docker 데몬에 연결


    %docker-machine env          
    export DOCKER_TLS_VERIFY="1"
    export DOCKER_HOST="tcp://192.168.99.100:2376"
    export DOCKER_CERT_PATH="/Users/da-shibata/.docker/machine/machines/default"
    export DOCKER_MACHINE_NAME="default"
    # Run this command to configure your shell: 
    # eval $(docker-machine env)
    

    상기 환경 변수는 이하의 command로 정리하여 설정함으로써 접속된다.
    %eval $(docker-machine env)
    

    가상 상자의 Docker 호스트에서 Apache 컨테이너 시작


    %docker run --name my-apache-app -p 8080:80 -v $PWD:/usr/local/apache2/htdocs/ httpd:2.4
    Unable to find image 'httpd:2.4' locally
    2.4: Pulling from library/httpd
    45b42c59be33: Already exists 
    83ac8490fcc3: Pull complete 
    bdb2d204d86d: Pull complete 
    243acf75a504: Pull complete 
    8fc1ad93a9b1: Pull complete 
    Digest: sha256:283f3c833adde108fc3d15c2ccac4b0ad4b650bc28821eafa02eb61f4d6a2c93
    Status: Downloaded newer image for httpd:2.4
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
    [Fri Mar 12 11:20:37.907850 2021] [mpm_event:notice] [pid 1:tid 140564998808704] AH00489: Apache/2.4.46 (Unix) configured -- resuming normal operations
    [Fri Mar 12 11:20:37.913294 2021] [core:notice] [pid 1:tid 140564998808704] AH00094: Command line: 'httpd -D FOREGROUND'
    

    -d를 붙여 잊으면 FOREGROUND로 실행되어 버리므로, 이렇게 프롬프트가 돌아오지 않게 된다.

    Apache 시작 확인



    시작은 OK
    $PWD를 지정한 것으로, 현재 디렉토리가 공개되어 버렸습니다만, 실제로 공개할 때는 호스트측의 디렉토리를 선택합시다.



    ※여기에서는 docker machine의 조작이 아닙니다. 호스트 OS에서 Apache 컨테이너를 시작하는 예입니다.

    로그를 확인하는 방법



    Apache를 백그라운드에서 시작


    % docker run -d --name apache -p 8080:80 -v $PWD:/usr/local/apache2/htdocs/ httpd:2.4
    Unable to find image 'httpd:2.4' locally
    2.4: Pulling from library/httpd
    6f28985ad184: Pull complete 
    3a141a09d1d0: Pull complete 
    1633384edb75: Pull complete 
    acb3e3b931b8: Pull complete 
    f6dc6b8b1d70: Pull complete 
    Digest: sha256:9625118824bc2514d4301b387c091fe802dd9e08da7dd9f44d93ee65497e7c1c
    Status: Downloaded newer image for httpd:2.4
    2563eba7e66ce7eb964049413d55effc7b54020ccf0f04337a71dfff7dfcee5d
    

    docker logs 명령 실행



    docker logs 다음에 컨테이너 ID 또는 컨테이너 이름을 지정하여 실행합니다.

    컨테이너 이름으로 지정한 경우


    % docker logs apache
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
    [Fri Mar 12 17:47:51.738784 2021] [mpm_event:notice] [pid 1:tid 139856445576320] AH00489: Apache/2.4.46 (Unix) configured -- resuming normal operations
    [Fri Mar 12 17:47:51.738995 2021] [core:notice] [pid 1:tid 139856445576320] AH00094: Command line: 'httpd -D FOREGROUND'
    172.17.0.1 - - [12/Mar/2021:17:48:47 +0000] "GET / HTTP/1.1" 200 1507
    172.17.0.1 - - [12/Mar/2021:17:48:59 +0000] "GET /favicon.ico HTTP/1.1" 404 196
    172.17.0.1 - - [12/Mar/2021:17:49:17 +0000] "GET / HTTP/1.1" 200 1507
    172.17.0.1 - - [12/Mar/2021:17:49:17 +0000] "GET / HTTP/1.1" 200 1507
    172.17.0.1 - - [12/Mar/2021:17:49:17 +0000] "GET / HTTP/1.1" 200 1507
    172.17.0.1 - - [12/Mar/2021:17:49:17 +0000] "GET / HTTP/1.1" 200 1507
    172.17.0.1 - - [12/Mar/2021:17:49:17 +0000] "GET / HTTP/1.1" 200 1507
    % 
    

    컨테이너 ID로 지정한 경우



    컨테이너 ID는 머리 2자리 정도 지정하면 OK
    % docker logs 25    
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
    [Fri Mar 12 17:47:51.738784 2021] [mpm_event:notice] [pid 1:tid 139856445576320] AH00489: Apache/2.4.46 (Unix) configured -- resuming normal operations
    [Fri Mar 12 17:47:51.738995 2021] [core:notice] [pid 1:tid 139856445576320] AH00094: Command line: 'httpd -D FOREGROUND'
    172.17.0.1 - - [12/Mar/2021:17:48:47 +0000] "GET / HTTP/1.1" 200 1507
    172.17.0.1 - - [12/Mar/2021:17:48:59 +0000] "GET /favicon.ico HTTP/1.1" 404 196
    172.17.0.1 - - [12/Mar/2021:17:49:17 +0000] "GET / HTTP/1.1" 200 1507
    172.17.0.1 - - [12/Mar/2021:17:49:17 +0000] "GET / HTTP/1.1" 200 1507
    172.17.0.1 - - [12/Mar/2021:17:49:17 +0000] "GET / HTTP/1.1" 200 1507
    172.17.0.1 - - [12/Mar/2021:17:49:17 +0000] "GET / HTTP/1.1" 200 1507
    172.17.0.1 - - [12/Mar/2021:17:49:17 +0000] "GET / HTTP/1.1" 200 1507
    172.17.0.1 - - [12/Mar/2021:17:50:08 +0000] "-" 408 -
    % 
    

    좋은 웹페이지 즐겨찾기