Reputation: 1266
Created docker image which will run perl script which internally triggers node servers using pm2 command.
Image created using dockerfile
FROM rm/node:4.0
EXPOSE 3000
EXPOSE 3030
EXPOSE 7030
WORKDIR /Reader_Manager/SISPlatform
CMD perl build_scripts/devdeploy.pl
When i run image in background using below command, it is executing the script. but after script completes it exits.
[dkanagaraj@localhost 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
[dkanagaraj@localhost 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.
[dkanagaraj@localhost 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
You can see above it was running and exposed to 3 ports. But it exits after perl script ends.
[dkanagaraj@localhost 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
Below are output from container logs
[dkanagaraj@localhost 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 'chai@^3.5.0' from dependencies
npm WARN package.json Dependency 'nodemon' exists in both dependencies and devDependencies, using 'nodemon@^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 'underscore@^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'
Upvotes: 0
Views: 1856
Reputation: 1266
Thank you all for your answers.
Adding pm2 logs (which runs a daemon to check the status of application) in CMD line in dockerfile fixed the issue.
CMD perl build_scripts/devdeploy.pl; pm2 logs
Upvotes: 0
Reputation: 21
The problem is that your entrypoint exits when it's finished, even if there are daemons running in the background. If you, for example, create a bash script that launchs the perl script and then launchs a tail -f of some log (your node log or app log) and use it as the entrypoint, you'll see your containers stay running.
Upvotes: 2