컨테이너화 및 WebServer

4550 단어 linuxdevopsdocker

웹서버란?



WebServer는 웹 서버 소프트웨어와 웹 사이트의 구성 요소 파일을 저장하는 컴퓨터입니다. (예: HTML, 이미지, 스크립트 등..) WebServer는 World Wide Web을 통해 클라이언트의 요청을 충족시키는 데 사용되는 서버 측 소프트웨어입니다. 웹 서버는 HTTP와 같은 프로토콜을 통해 작동하며 들어오는 요청을 처리합니다.

If you are not familiar with Docker and have not installed Docker in your device, you can go through my article mentioning installation Containerization and Docker and Getting familiar with Docker.



CentOS 컨테이너에서 Apache 서버 설정



CentOS 컨테이너 실행




  • 먼저 다음 명령을 사용하여 수행할 수 있는 DockerHub에서 CentOS 이미지를 가져와야 합니다.

  • docker pull centos
    


  • 또한 실행 명령을 사용하여 Docker 컨테이너를 시작해야 합니다.

  • docker run -it --name web-server centos
    


  • 이제 주어진 명령을 사용하여 수행할 수 있는 CentOS 컨테이너에 일부 패키지를 설치해야 합니다.

  • dnf install ncurses psmisc vim net-tools httpd -y
    


    ncurses: Installs the clear command

    psmisc: Installs the killall command

    vim: Installs the text editor

    net-tools: Installs the ifconfig and netstat command

    httpd: Installs the Apache Web Server



    이제 컨테이너가 완전히 설정되었으며 추가 구성에 사용할 준비가 되었습니다.

    웹 서버 구성




  • WebServer를 구성하려면 먼저 Apache WebServer의 서비스를 시작해야 하지만 Docker 컨테이너에는 트위스트가 있습니다.
    > 컨테이너에 PID-1이 포함되어 있지 않기 때문에 Docker에서 systemctl 명령을 사용할 수 없습니다.

  • /usr/sbin/httpd
    


    위의 명령은 webservices를 활성화하고 systemctl이 작동하지 않으므로 아래에 제공된 netstat 명령을 사용하여 서비스를 확인할 수 있습니다.

    netstat -tnlp
    


  • 이제/var/www/html에 있는 Apache WebServer 문서 루트에 WebServer 파일을 넣어야 합니다.

  • /var/www/html
    


  • 이제 웹 서버의 IP에 있는 파일에 액세스할 수 있습니다.

  • http://IP_ADDRESS/FILE:PORT_NO
    


    If we are using the default 80 port we need not to specify the port number as browser itself use the 80 port.



    WebServer를 영구적으로 만들기



    WebServer는 Docker 컨테이너를 중지하면 중지되며 부팅 시 서비스를 시작하기 위해 .bashrc 파일에 서비스를 추가해야 하는 경우 다시 시작되지 않습니다. 또한/var/run/httpd 폴더에 있는 파일을 제거해야 합니다. pid는 현재 실행 중인 httpd 프로세스에 대해 지정된 폴더에 저장되어 있고 컨테이너를 중지하고 다시 시작할 때 processid가 제거되지 않기 때문입니다.

    echo "rm -rf /var/run/httpd/*" >> .bashrc
    echo "/usr/sbin/httpd" >> .bashrc
    


    We are updating the .bashrc file as it is the script that gets executed when a user logs in. The file itself contains a series of configurations for the terminal session.



    컨테이너에서 Docker 이미지 생성




  • docker ps 명령을 사용하여 docker 컨테이너 정보를 확인합니다.

  • docker ps
    


  • docker commit 명령을 사용하여 다음 구문을 사용하여 docker 컨테이너의 이미지를 만듭니다.

  • docker commit CONTAINER_NAME IMAGE_NAME:VERSION
    


    Following command will create a docker image from the given container.

    1. Check if the image is present using the docker images command.


    docker images
    


    Now the WebServer has been configured on the CentOS container and can be used using the new Docker Image.

    좋은 웹페이지 즐겨찾기