2016-06-06 2 views
0

pm2 명령을 사용하여 노드 서버를 내부적으로 트리거하는 perl 스크립트를 실행할 고정 된 도커 이미지가 작성되었습니다.종료하지 않고 도커 이미지 (nodejs 서버)를 실행하는 방법

이미지는 내가 명령 아래 사용하여 배경 이미지를 실행하면 스크립트를 실행하고,

FROM rm/node:4.0 
EXPOSE 3000 
EXPOSE 3030 
EXPOSE 7030 

WORKDIR /Reader_Manager/SISPlatform 
CMD perl build_scripts/devdeploy.pl 

dockerfile 사용하여 만들었습니다. 스크립트가 완료된 후에 스크립트는 종료됩니다.

[[email protected] docker_test]$ docker images 
REPOSITORY   TAG     IMAGE ID   CREATED    VIRTUAL SIZE 
rm/node    8.0     716f9b91b9f2  23 minutes ago  1.376 GB 
rm/node    7.0     805fced7c1c8  3 hours ago   1.376 GB 
rm/node    6.0     4b0746c90363  3 hours ago   1.376 GB 
rm/node    5.0     912588196f44  7 hours ago   1.376 GB 
rm/node    4.0     22d40a764333  3 days ago   1.376 GB 
rm/node    3.0     dc344c502819  3 days ago   999.1 MB 
rm/node    2.0     bee03055f04c  3 days ago   824.7 MB 
rm/node    1.0     b9fa60c9f544  3 days ago   488.8 MB 
docker.io/centos latest    a65193109361  3 days ago   196.7 MB 

[[email protected] docker_test]$ docker run -d rm/node:8.0 
a2d1780ce3dcf102fd2a0eb4d6632f6934f8c0a5362e0312b117e8da77c1c242 
Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning. 

[[email protected] docker_test]$ docker ps 
CONTAINER ID  IMAGE    COMMAND     CREATED    STATUS    PORTS       NAMES 
a2d1780ce3dc  rm/node:8.0   "/bin/sh -c 'perl bui" 8 seconds ago  Up 7 seconds  3000/tcp, 3030/tcp, 7030/tcp goofy_brattain 

위에서 볼 수 있듯이 3 개의 포트가 있습니다. 하지만 perl 스크립트가 끝난 후에 종료됩니다. 다음은

[[email protected] docker_test]$ docker ps -a |head -2 
CONTAINER ID  IMAGE    COMMAND     CREATED    STATUS      PORTS    NAMES 
a2d1780ce3dc  rm/node:8.0   "/bin/sh -c 'perl bui" 9 minutes ago  Exited (0) 8 minutes ago      goofy_brattain 

[[email protected] docker_test]$ docker logs a2d1780ce3dc |tail -25 
[PM2][WARN] No process found 
npm WARN package.json Dependency 'chai' exists in both dependencies and devDependencies, using '[email protected]^3.5.0' from dependencies 
npm WARN package.json Dependency 'nodemon' exists in both dependencies and devDependencies, using '[email protected]^1.8.1' from dependencies 
npm WARN cannot run in wd [email protected] node postinstall.js (wd=/Reader_Manager/SISPlatform/Auth) 
npm WARN package.json [email protected] No description 
npm WARN package.json [email protected] No repository field. 
npm WARN package.json [email protected] No README data 
npm WARN package.json Dependency 'underscore' exists in both dependencies and devDependencies, using '[email protected]^1.8.3' from dependencies 
npm WARN package.json [email protected] No description 
npm WARN package.json [email protected] No repository field. 
npm WARN package.json [email protected] No README data 
┌─────────────┬────┬──────┬─────┬────────┬─────────┬────────┬─────────────┬──────────┐ 
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory  │ watching │ 
├─────────────┼────┼──────┼─────┼────────┼─────────┼────────┼─────────────┼──────────┤ 
│ AuthServer │ 0 │ fork │ 74 │ online │ 0  │ 2s  │ 63.191 MB │ disabled │ 
│ SISRMServer │ 1 │ fork │ 107 │ online │ 0  │ 1s  │ 63.355 MB │ disabled │ 
│ SEOSServer │ 2 │ fork │ 138 │ online │ 0  │ 0s  │ 13.957 MB │ disabled │ 
└─────────────┴────┴──────┴─────┴────────┴─────────┴────────┴─────────────┴──────────┘ 
Use `pm2 show <id|name>` to get more details about an app 


     [Output] - Successfully executed 'npm run-script dev-server-linux' inside '/Reader_Manager/SISPlatform/SEOS-TSMWrapper' 

     [Output] - Current working directory is /Reader_Manager/SISPlatform 

     [Output] - Checking the errors in the logs '/Reader_Manager/SISPlatform/logs/pm2/err' 


     [Output] - No error in the log '/Reader_Manager/SISPlatform/logs/pm2/err/auth_error-0.log' 


     [Output] - No error in the log '/Reader_Manager/SISPlatform/logs/pm2/err/seos_error-2.log' 


     [Output] - No error in the log '/Reader_Manager/SISPlatform/logs/pm2/err/sisrm_error-1.log' 
+0

PM2는이 문제를 해결 것이지만, 이상적으로 별도의 용기에 각 서비스를 배포하는 것 모두에 PM2를 사용하지 않는'--no-daemon' 옵션 (부두 노동자가'--restart와 기본적으로 다시 시작 핸들을 가지고 = 항상'). – jgillich

답변

1

문제는 당신의 엔트리 포인트 종료가이 백그라운드에서 실행되는 데몬가있는 경우에도, 완료 때이다 컨테이너 로그에서 출력됩니다. 예를 들어, perl 스크립트를 실행 한 bash 스크립트를 만든 다음 일부 로그 (노드 로그 또는 응용 프로그램 로그)의 tail -f를 실행하고이를 엔트리 포인트로 사용하면 컨테이너가 계속 실행되는 것을 볼 수 있습니다.

0

답장을 보내 주셔서 감사합니다.

dockerfile의 CMD 줄에서 pm2 로그 (응용 프로그램의 상태를 검사하는 데몬을 실행 함)를 추가하면 문제가 해결되었습니다.

CMD perl build_scripts/devdeploy.pl; pm2 logs 
관련 문제