CentOS7 Docker Nginx를 배포하고 실행하는 방법
1. 리소스 준비
dockerfile 파일
# "ported" by adam miller <maxamillion@fedoraproject.org> from # https://github.com/fedora-cloud/fedora-dockerfiles # # originally written for fedora-dockerfiles by # scollier <scollier@redhat.com> from centos:centos7 maintainer the centos project <cloud-ops@centos.org> run yum -y update; yum clean all run yum -y install epel-release tar ; yum clean all run yum -y install nginx ; yum clean all add nginx.conf /opt/deploy/nginx/nginx.conf run echo "daemon off;" >> /opt/deploy/nginx/nginx.conf #run curl https://git.centos.org/sources/httpd/c7/acf5cccf4afaecf3afeb18c50ae59fd5c6504910 \ # | tar -xz -c /usr/local/nginx/html \ # --strip-components=1 #run sed -i -e 's/apache/nginx/g' -e '/apache_pb.gif/d' \ # /usr/local/nginx/html/index.html expose 80 #cmd [ "/usr/local/nginx/sbin" ]
참고: 경로는 시스템에 존재해야 하며
nginx.conf 파일
# for more information on configuration, see: # * official english documentation: http://nginx.org/en/docs/ # * official russian documentation: http://nginx.org/ru/docs/ user nginx; worker_processes 1; error_log /usr/logs/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /run/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /usr/logs/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; # load modular configuration files from the /etc/nginx/conf.d directory. # see http://nginx.org/en/docs/ngx_core_module.html#include # for more information. #include /etc/nginx/conf.d/*.conf; index index.html index.htm; server { listen 80; server_name localhost; root /usr/share/nginx/html; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { autoindex on; } # redirect server error pages to the static page /40x.html # error_page 404 /404.html; location = /40x.html { } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { } # proxy the php scripts to apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the php scripts to fastcgi server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param script_filename /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of ip-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # root html; # location / { # } #} # https server # #server { # listen 443; # server_name localhost; # root html; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols sslv2 sslv3 tlsv1; # ssl_ciphers high:!anull:!md5; # ssl_prefer_server_ciphers on; # location / { # } #} }
과 일치해야 합니다. 경로는 시스템에 존재하고 일치해야 합니다
2. 빌드 이미지 명령 실행
코드 복사 코드는 다음과 같습니다.
[root@localhost nginx]# sudo docker build --rm --tag os7/nginx:centos7
실행 스크린샷. 결과:
3. docker 이미지가 성공적으로 설치되고 빌드되었는지 확인하세요. bin/bash
참고: IP가 192.168.32.129 인 경우 /etc/hosts localhost
5에
192.168.32.129를 추가해야 합니다. 컨테이너가 성공적으로 생성되었는지 확인하고 docker ps
를 시작합니다.
6. 컬 http://192.168.32.129에 성공적으로 접속했는지 테스트하세요:81
이 연결이 거부되었습니다. 어떻게 해야 하나요? 해결 방법이 있으니 먼저 컨테이너에 들어가 보겠습니다
7. 컨테이너에 docker exec -i -t small_hodgkin /bin/sh
8을 입력합니다.
nginx
9. 컨테이너 외부에서 컬 http://192.168.32.129:81 실행이 성공했습니다.
10. 가상머신 외부의 브라우저를 통해 접속하세요
위 내용은 CentOS7 Docker Nginx를 배포하고 실행하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Docker 이미지를 업데이트하는 단계는 다음과 같습니다. 최신 이미지 태그 가져 오기 새 이미지 특정 태그의 이전 이미지 삭제 (선택 사항) 컨테이너를 다시 시작하십시오 (필요한 경우)

도커 컨테이너를 종료하는 4 가지 명령 사용 Docker Kill & lt; Container_name & gt; 호스트 터미널의 명령 (힘 출구)

Docker의 외부 호스트에 파일을 복사하는 방법 : Docker CP 명령 사용 : Docker CP 실행 [옵션] & lt; 컨테이너 경로 & gt; & lt; 호스트 경로 & gt;. 데이터 볼륨 사용 : 호스트에서 디렉토리를 만들고 -V 매개 변수를 사용하여 양방향 파일 동기화를 달성하기 위해 컨테이너를 만들 때 컨테이너에 디렉토리를 장착하십시오.

Docker 컨테이너를 다시 시작하는 방법 : 컨테이너 ID (Docker PS)를 가져옵니다. 컨테이너 중지 (Docker Stop & lt; container_id & gt;); 컨테이너를 시작하십시오 (Docker start & lt; container_id & gt;); 재시작이 성공했는지 확인하십시오 (Docker PS). 기타 방법 : Docker Compose (Docker-Compose Restart) 또는 Docker API (Docker 문서 참조).

Docker Desktop을 사용하는 방법? Docker Desktop은 로컬 머신에서 Docker 컨테이너를 실행하는 도구입니다. 사용 단계는 다음과 같습니다. 1. Docker Desktop 설치; 2. Docker Desktop을 시작하십시오. 3. Docker 이미지를 만듭니다 (Dockerfile 사용); 4. Docker Image 빌드 (Docker 빌드 사용); 5. 도커 컨테이너를 실행하십시오 (Docker Run 사용).

도커 프로세스보기 방법 : 1. Docker CLI 명령 : Docker PS; 2. Systemd Cli 명령 : SystemCTL 상태 Docker; 3. Docker Compose CLI 명령 : Docker-Compose PS; 4. 프로세스 탐색기 (Windows); 5. /Proc Directory (Linux).

단계를 따르면 Docker 컨테이너 이름을 쿼리 할 수 있습니다. 모든 컨테이너 (Docker PS)를 나열하십시오. 컨테이너 목록을 필터링합니다 (GREP 명령 사용). 컨테이너 이름 ( "이름"열에 위치)을 가져옵니다.

실패한 Docker 이미지 빌드에 대한 문제 해결 단계 : Dockerfile 구문 및 종속성 버전을 확인하십시오. 빌드 컨텍스트에 필요한 소스 코드 및 종속성이 포함되어 있는지 확인하십시오. 오류 세부 사항에 대한 빌드 로그를보십시오. -표적 옵션을 사용하여 계층 적 단계를 구축하여 실패 지점을 식별하십시오. 최신 버전의 Docker Engine을 사용하십시오. -t [image-name] : 디버그 모드로 이미지를 빌드하여 문제를 디버깅하십시오. 디스크 공간을 확인하고 충분한 지 확인하십시오. 빌드 프로세스에 대한 간섭을 방지하기 위해 Selinux를 비활성화하십시오. 커뮤니티 플랫폼에 도움을 요청하고 Dockerfiles를 제공하며보다 구체적인 제안을 위해 로그 설명을 구축하십시오.
