React.js에 대한 자습서를 작성 중이며 Docker 컨테이너에서 작업하기로 결정했습니다. Here은 자습서의 코드입니다.호스트 (노출 된 게시 됨) 포트에 연결할 수 없습니다.
자습서에서는 webpack-dev-server
을 컨테이너의 포트 8080에서 실행합니다. 내 Dockerfile
에이 포트를 노출하고, -P
내 컨테이너를 실행 포트를 게시 할 수 있습니다. 컨테이너 내부에서 wget http://localhost:8080
인 경우 index.html
을 예상대로 다운로드합니다. 그러나 내 호스트에서 동등한 PowerShell 명령 Invoke-WebRequest http://localhost:32769
을 실행하면 Invoke-WebRequest : The underlying connection was closed: The connection was closed unexpectedly.
전체 세부 정보/복구 단계가 표시됩니다.
# In a separate terminal
PS C:\Users\matth> docker exec -it repro bash
[email protected]:/# wget http://localhost:8080
... # index.html is downloaded as expected
[email protected]:/# exit
exit
PS C:\Users\matth> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd6c3102bc51 mpiroc/react-fundamentals "node" 28 minutes ago Up 28 minutes 0.0.0.0:32769->8080/tcp repro
PS C:\Users\matth> Invoke-WebRequest http://localhost:32769
Invoke-WebRequest : The underlying connection was closed: The connection was closed unexpectedly.
At line:1 char:1
+ Invoke-WebRequest http://localhost:32769
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
왜 내 호스트 컴퓨터에서 게시 된 포트에 액세스 할 수있는 용기를 테스트
Dockerfile
FROM node
MAINTAINER Matthew Pirocchi <[email protected]>
RUN apt-get update && apt-get install -y vim
EXPOSE 8080
컨테이너 설정
docker run -itdP --name repro mpiroc/react-fundamentals
docker exec -it repro bash
# Following commands executed within container
mkdir -p /home/mpiroc/repos && cd /home/mpiroc/repos
git clone https://github.com/ReactjsProgram/React-Fundamentals.git
cd React-Fundamentals
git checkout video2
npm install
npm run start # start just runs `webpack-dev-server`
컨테이너에서 로컬 호스트에서만 수신 대기하는 경우 해당 포트가 컨테이너 외부에서 포트 전달에 표시되지 않습니다. – BMitch