Git Product home page Git Product logo

docker-pm2's Introduction

PM2

Production ready nodeJS Docker image including the PM2 runtime.

The goal of this image is to wrap your applications into a proper Node.js production environment. It solves major issues when running Node.js applications inside a container like:

  • Correct PID 1 signals Handling & Forwarding
  • Graceful application Start and Shutdown
  • Seamless application clustering to increase performance and reliability

Further than that, using PM2 as a layer between the container and the application brings PM2 features like application declaration file, customizable log system, source map support and other great features to manage your Node.js application in production environment.

Tags available

Image Name Operating system Dockerfile
keymetrics/pm2:latest-alpine Alpine latest-alpine
keymetrics/pm2:18-alpine Alpine 15-alpine
keymetrics/pm2:16-alpine Alpine 15-alpine
keymetrics/pm2:15-alpine Alpine 15-alpine
keymetrics/pm2:14-alpine Alpine 14-alpine
keymetrics/pm2:12-alpine Alpine 12-alpine
keymetrics/pm2:10-alpine Alpine 10-alpine
Image Name Operating system Dockerfile
keymetrics/pm2:latest-buster DebianΒ Buster latest-buster
keymetrics/pm2:18-buster DebianΒ Buster 18-buster
keymetrics/pm2:16-buster DebianΒ Buster 16-buster
keymetrics/pm2:15-buster DebianΒ Buster 15-buster
keymetrics/pm2:14-buster DebianΒ Buster 14-buster
keymetrics/pm2:12-buster DebianΒ Buster 12-buster
keymetrics/pm2:10-buster DebianΒ Buster 10-buster
Image Name Operating system Dockerfile
keymetrics/pm2:latest-stretch DebianΒ Stretch latest-stretch
keymetrics/pm2:18-stretch DebianΒ Stretch 18-stretch
keymetrics/pm2:16-stretch DebianΒ Stretch 16-stretch
keymetrics/pm2:15-stretch DebianΒ Stretch 15-stretch
keymetrics/pm2:14-stretch DebianΒ Stretch 14-stretch
keymetrics/pm2:12-stretch DebianΒ Stretch 12-stretch
keymetrics/pm2:10-stretch DebianΒ Stretch 10-stretch
Image Name Operating system Dockerfile
keymetrics/pm2:latest-jessie DebianΒ Jessie latest-jessie
keymetrics/pm2:18-jessie DebianΒ Jessie 18-jessie
keymetrics/pm2:16-jessie DebianΒ Jessie 16-jessie
keymetrics/pm2:15-jessie DebianΒ Jessie 15-jessie
keymetrics/pm2:14-jessie DebianΒ Jessie 14-jessie
keymetrics/pm2:12-jessie DebianΒ Jessie 12-jessie
keymetrics/pm2:10-jessie DebianΒ Jessie 10-jessie
Image Name Operating system Dockerfile
keymetrics/pm2:latest-slim DebianΒ Stretch (minimal packages) latest-slim
keymetrics/pm2:18-slim DebianΒ Stretch (minimal packages) 18-slim
keymetrics/pm2:16-slim DebianΒ Stretch (minimal packages) 16-slim
keymetrics/pm2:15-slim DebianΒ Stretch (minimal packages) 15-slim
keymetrics/pm2:14-slim DebianΒ Stretch (minimal packages) 14-slim
keymetrics/pm2:12-slim DebianΒ Stretch (minimal packages) 12-slim
keymetrics/pm2:10-slim DebianΒ Stretch (minimal packages) 10-slim

You can find more information about the image variants here.

The build process of these images is automatically triggered each time NodeJS's Docker images are built. The build process of these images is automatically triggered each time Docker PM2's GitHub repo master branch is pushed. The build process of these images is automatically triggered each time PM2's GitHub repo master branch is pushed.

Usage

Let's assume the following folder structure for your project.

`-- your-app-name/
    |-- src/
 Β       `-- app.js
 Β   |-- package.json
 Β   |-- pm2.json     (we will create this in the following steps)
    `-- Dockerfile   (we will create this in the following steps)

Create a pm2 ecosystem file

Create a new file called pm2.json with the following content:

{
  "name": "your-app-name",
  "script": "src/app.js",
  "instances": "2",
  "env": {
    "NODE_ENV": "development"
  },
  "env_production" : {
    "NODE_ENV": "production"
  }
}

You can choose the name of the ecosystem file arbitrarily, but we will assume you called it pm2.json in the following steps.

See the documentation for more information about how to configure the ecosystem file.

Create a Dockerfile file

Create a new file called Dockerfile with the following content:

FROM keymetrics/pm2:latest-alpine

# Bundle APP files
COPY src src/
COPY package.json .
COPY pm2.json .

# Install app dependencies
ENV NPM_CONFIG_LOGLEVEL warn
RUN npm install --production

# Show current folder structure in logs
RUN ls -al -R

CMD [ "pm2-runtime", "start", "pm2.json" ]

See the documentation for more info about the pm2-runtime command.
All options available are listed here.

Build and Run your image

From your Node.js app project folder launch those commands:

$ docker build -t your-app-name .
$ docker run your-app-name

Custom configurations

Enable git auto-pull

If you want to Automatically synchronize your application with git add this into your Dockerfile:

RUN pm2 install pm2-auto-pull

Make sure the .git is present in your application source folder.

Enable Monitor server

If you want to Automatically monitor vital signs of your server add this into your Dockerfile:

RUN pm2 install pm2-server-monit

Use Keymetrics.io dashboard

Keymetrics.io is a monitoring service built on top of PM2 that allows to monitor and manage applications easily (logs, restart, exceptions monitoring, etc...). Once you created a Bucket on Keymetrics you will get a public and a secret key.

To enable Keymetrics monitoring with pm2-runtime, you can whether use the CLI option –public XXXX and –secret YYYY or you can pass the environment variables KEYMETRICS_PUBLIC and KEYMETRICS_SECRET.

From your Node.js app project folder launch those commands:

$ docker build -t your-app-name .
$ docker run -e KEYMETRICS_PUBLIC=XXXX -e KEYMETRICS_SECRET=YYYY your-app-name

Make sure that the ports 80 (TCP outbound), 443 (HTTPS outbound) and 43554 (TCP outbound) are allowed on your firewall.

See the troubleshooting in case you encounter any problem.

Enabling Graceful Shutdown

When the Container receives a shutdown signal, PM2 forwards this signal to your application allowing to close all the database connections, wait that all queries have been processed or that any other final processing has been completed before a successful graceful shutdown.

Catching a shutdown signal is straightforward. You need to add a listener in your Node.js applications and execute anything needed before stopping the app:

process.on('SIGINT', function() {
  db.stop(function(err) {
    process.exit(err ? 1 : 0);
  });
});

By default PM2 will wait 1600ms before sending a final SIGKILL signal. You can modify this delay by setting the kill_timeout option inside your application configuration file.

Expose health endpoint

The --web [port] option allows to expose all vital signs (docker instance + application) via a JSON API.

CMD ["pm2-runtime", "start", "pm2.json", "--web"]

or

CMD ["pm2-runtime", "start", "pm2.json", "--web", "port"]

Useful commands

Command Description
$ docker exec -it <container-id> pm2 monit Monitoring CPU/Usage of each process
$ docker exec -it <container-id> pm2 list Listing managed processes
$ docker exec -it <container-id> pm2 show Get more information about a process
$ docker exec -it <container-id> pm2 reload all 0sec downtime reload all applications

Documentation

The documentation can be found here.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

License information for the software contained in this image can be found here (pm2) and here (node).

docker-pm2's People

Contributors

houssem-yahiaoui avatar shako92 avatar simonepri avatar timmikeladze avatar unitech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-pm2's Issues

Dockerfile based on centos7

I built my Dockerfile based on centos7.
but cannot run container.

****** Docker file ***********
FROM centos:centos7

RUN curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash && source ~/.bashrc && nvm install stable && npm install pm2 -g

VOLUME ["/agent"]

EXPOSE 80 443 43554

WORKDIR /agent

CMD /bin/bash pm2-docker start --auto-exit --env production process.yml


after cli command "docker run -it --name testagent myimage"
it says "/bin/bash: pm2-docker: No such file or directory"

but after command "docker run -it --name testagent myimage /bin/bash" ,
I can run pm2-docker command.

what should I do?
what is my mistake?
( do not care about /agent/process.yml, I have mounted with mesos-marathon )

License in README.md is inconsistent with LICENSE file

The License section in README.md says:

This project is licensed under the GPL-3.0 License - see the LICENSE file for details.

While the LICENSE file is copy of the MIT license, which seems to be the intended license as it is newer in the commit history.

Please update the readme or license file to be consistent, because some organizations have restrictions against using GPL software.

docker-pm2 for arm64

Hi,

I would like to be able to run docker-pm2 on my rapsberry pi 3 (arm64 with Hypriot OS) but I believe that the available images are not compatible with such a system architecture (no aarch64 || arm64 || arm32 images).

I'm quite new with Docker ^^.

Thanks

Improve Graceful Shutdown

Our example about how to implement a serious graceful shutdown is too minimalist.
It's good as example but it's not enough in production environments.

Some days ago I've found this amazing package made from @Tappi and @sindresorhus that enable us to implement a more rigid graceful shutdown.

This is an example of implementation:

const exitHook = require('async-exit-hook');

// Set this with the same value of 'kill_timeout'
exitHook.forceExitTimeout(1600);

// The exit callback.
// This will be always called before the server exits
exitHook(cb => {
  server.close(() => {
    db.stop(function(err) {
      cb(); // When you have ended your cleanup operations
    });
  })
});

// Called after an uncaught exception.
// The exit callback will called after this.
exitHook.uncaughtExceptionHandler((err, cb) => {
  // Log the error on the console
  console.log(err);
  cb();
});

// Called after an unhandled rejection.
// The exit callback will called after this.
exitHook.unhandledRejectionHandler((err, cb) => {
  // Log the error on the console
  console.log(err);
  cb();
});

I think we should add a better example, maybe suggesting users to use the package mentioned before.
But if we do so we should write something that explains why to use this package and how.

Any thoughts on this?

Add git

It'd be nice if the containers had git support added so packages can be installed from git addresses.

Ref: npm/npm#17985

Why there is exposed ports?

My app run on port 5000

but with pm2, i see this

  "ExposedPorts": {
                "5000/tcp": {},
                "43554/tcp": {},
                "443/tcp": {},
                "80/tcp": {}
            },

Why this happening? Why these ports exposed?

Unable to set port for --web option

I'm trying to expose my web healthcheck on a port other than the default (9615). However, I can't seem to get pm2 to listen on anything other than the default. I've tried the following command:

CMD ["pm2-docker", "start", "pm2.json", "--web", "port"]

Where "port" the actual port number I'm trying to use. Is there something that I'm missing? I've tried the "--web" option in various positions without success.

Thanks for your help!

How can I run NPM commands on "watch"?

Hey maintainers, thanks very much for your hard work!

I would like to run an NPM command every time pm2-docker restarts from a "watch". This is my package.json file:

{
  "name": "my app",
  "scripts": {
    "eslint": "eslint */**.js",
    "start": "pm2-docker process.yml --watch"
  }
}

And then I have a process.yml file:

apps:
  - script   : 'app.js'
    exec_mode: 'cluster'
    instances: 4

The --watch flag run correctly every time I update my JS files, but I would also like to run npm run lint on each watch.

Is this possible?

PM2 Official Docker Repository

As discussed in #25 it would be interesting to see if we can publish this image as "Official" on the Docker Hub.

The process seems quite simple. We have to simply open a PR here adding a file called pm2 inside the library folder of the repo.

The pm2 file can be generated automagically using this script i wrote.

So why we don't do that?
It seems that the images are rebuilt manually by the docker team. This means that we are not able to setup any sort of automated build like the one we have now.

Can I use certain options in pm2-runtime?

pm2-runtime app/main.js --kill-timeout=6000 --no-treekill

error: unknown option `--kill-timeout'

I want to use the --kill-timeout and --no-treekill options in pm2-runtime.
But it does not work.
How can I get it to work?``

How can I run the container follow the Usage Guide

  1. Create a Dockerfile in your Node.js app project
  2. Create a pm2.json in your Node.js app project
  3. Build and Run your image
$ docker build -t your-app-name .

Sending build context to Docker daemon 51.42 MB
Step 1 : FROM keymetrics/pm2-docker-alpine:latest
 ---> fea23810c91d
Step 2 : CMD pm2-docker --json start ./pm2.json
 ---> Running in 2c3179e30171
 ---> 193f478715cb
Removing intermediate container 2c3179e30171
Successfully built 193f478715cb

$ docker run your-app-name .

container_linux.go:247: starting container process caused "exec: \".\": executable file not found in $PATH"
docker: Error response from daemon: containerd: container not started.

node_modules directory not created using dockerfile example. No error messages

I'm using your dockerfile as suggested on https://hub.docker.com/r/keymetrics/pm2/ but there is no node_modules directory created.

my docker version is 17.09.0-ce, build afdb6d4

Below is the output of the docker build command. As you can see there is no node_modules so the javascript program will fail with module xxx not found.

When I run the container interactively (first installing a bash shell with RUN apk add --no-cache bash in the dockerfile) and run NPM install, it will install the dependencies in the /app folder without errors.

I don't know how to solve this. I hope somebody sess what I'm doing wrong.
Thanks.

Output of docker build:

Step 7/12 : ENV NPM_CONFIG_LOGLEVEL warn
 ---> Using cache
 ---> 9fdec208e92e
Step 8/12 : RUN npm install
 ---> Running in 0c0912ab16e5
added 355 packages in 24.476s
 ---> 57ed4e10162e
Removing intermediate container 0c0912ab16e5
Step 9/12 : RUN ls -al -R
 ---> Running in b05074ef2642
.:
total 20
drwxr-xr-x    3 root     root          4096 Nov  6 08:16 .
drwxr-xr-x   51 root     root          4096 Nov  6 08:16 ..
drwxr-xr-x    4 root     root          4096 Nov  6 08:14 app
-rw-r--r--    1 root     root          1540 Nov  6 05:14 package.json
-rw-r--r--    1 root     root           179 Nov  6 05:03 pm2.json

My dockerfile:

FROM keymetrics/pm2:8

# Bundle APP files
COPY app app/
COPY package.json .
COPY pm2.json .

# Install bash shell
# RUN apk add --no-cache bash

# Install app dependencies
ENV NPM_CONFIG_LOGLEVEL warn
RUN npm install --production

# Show current folder structure in logs
RUN ls -al -R

# Expose ports
EXPOSE 80 443 3333 43554

CMD [ "pm2-docker", "start", "pm2.json" ]

My package.json file:

{
  "name": "microservices",
  "version": "1.0.10",
  "description": "Broker microservice for cloud trader",
  "repository": {
    "type": "git",
    "url": "git+https://gitlab.com/edelacruz/cloudtrader-microservices"
  },
  "main": "index.js",
  "scripts": {
    "start": "pm2 start process.yml",
    "prestart": "pm2 stop process.yml && pm2 delete process.yml",
    "stop": "pm2 stop process.yml && pm2 delete process.yml",
    "test": "mocha ./test",
    "version:patch": "npm version patch -m 'Upgrade to %s'",
    "version:release": "npm version major",
    "push": "npm run version:patch && git push --tags origin master",
    "build": "npm test && npm run push",
    "docker-build": "docker build -t cloudtrader/microservices:latest .",
    "docker-run": "docker run --name micro -p 3333:3333 --net host cloudtrader/microservices:latest"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "async": "^2.5.0",
    "debug": "^2.6.9",
    "ioredis": "^3.2.1",
    "jsonwebtoken": "^7.4.3",
    "mongodb": "^2.2.33",
    "querystring": "^0.2.0",
    "socket.io-client": "^2.0.4",
    "winston": "^2.4.0",
    "winston-loggly-bulk": "^2.0.1",
    "ws": "^3.2.0"
  },
  "devDependencies": {
    "chai": "^4.0.2",
    "chai-as-promised": "^7.1.1",
    "mocha": "^3.4.2",
    "standard": "^10.0.3"
  },
  "standard": {
    "env": [
      "mocha",
      "chai"
    ],
    "globals": [
      "describe",
      "context",
      "before",
      "beforeEach",
      "after",
      "afterEach",
      "it",
      "expect"
    ]
  }
}

Change of direction

After the discussion here I've thought that maybe we can re-think the objective of the images that we ship on the Docker Hub.

Now, basically, we publish 20 images that just adds pm2 on the official node Docker repo.
While they can be useful for some, the truth is that, as pointed out here, they may not be real value added for the community. (Even if there are more than 10k pull from the Docker Hub)

I believe that the common user just want to have a "production ready" container to ship his services.
BUT the node's official images aren't suited for production.
So, in that sense, it wouldn't be better to build our own HARDENED image that the users can pull and run?

Something like docker-alpine-hardened image.

@Unitech @vmarchaud What do you think?
Is there a way to get some feedbacks from pm2's users?

TypeError: Cannot read property 'pm2_env' of undefined

I haven't been able to get docker-pm2 running because this particular error,

i am using Hapijs as framework
this is my pm2.json

{
  "apps": [{
    "name": "dockered-node",
    "script": "server.js",
    "env": {
      "production": true
    }
  }]
}

and this my Dockerfile

FROM keymetrics/pm2:latest
COPY package.json .
COPY pm2.json .
ENV NPM_CONFIG_LOGLEVEL warn
RUN npm install --production
RUN ls -al -R
CMD [ "pm2-docker", "start", "pm2.json" ]
EXPOSE 8000

TypeError: Cannot read property 'pm2_env' of undefined
at /usr/local/lib/node_modules/pm2/lib/binaries/Runtime4Docker.js:94:26
at /usr/local/lib/node_modules/pm2/lib/API.js:1009:21
at /usr/local/lib/node_modules/pm2/lib/API.js:1080:19
at /usr/local/lib/node_modules/pm2/node_modules/async/dist/async.js:473:16
at replenish (/usr/local/lib/node_modules/pm2/node_modules/async/dist/async.js:993:25)
at iterateeCallback (/usr/local/lib/node_modules/pm2/node_modules/async/dist/async.js:98
at /usr/local/lib/node_modules/pm2/node_modules/async/dist/async.js:958:16
at /usr/local/lib/node_modules/pm2/lib/API.js:1046:16
at /usr/local/lib/node_modules/pm2/node_modules/async/dist/async.js:3096:16
at replenish (/usr/local/lib/node_modules/pm2/node_modules/async/dist/async.js:998:17)

Change repo description.

Emoji are cool 😎
What if we change the description of the repo
From:

Node.js lightweight Docker image including the PM2 runtime

To:

🐳 Official Docker Image for PM2 runtime

keymetrics/pm2:8-alpine broken at runtime

keymetrics/pm2:8-alpine broken at runtime

After last build pm2:8-alpine is broken at runtime, complains about date-fns package.

Steps to reproduce: docker run keymetrics/pm2:8-alpine

Error sysout:

module.js:550
    throw err;
    ^

Error: Cannot find module './add_days/index.js'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/pm2/node_modules/date-fns/index.js:2:12)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)

pm2-dev does not restart server on file changes

I have the following docker-compose.yml file:

version: '3.2'

services:
  backend:
    image: keymetrics/pm2-docker-alpine:8
    ports:
      - 3000:3000
    working_dir: /var/www
    command: ["pm2-dev", "start", "process.yml"]
    volumes:
      - "../..:/var/www"

I am further using the following process.yml pm2 configuration:

---
apps:
  - script: 'src/server.js'
    name: 'my-app'
    interpreter: 'babel-node'
    cwd: '/var/www'

The app starts alright. Unfortunately, it does not react to file changes. docker exec -it <container_id> sh 'ing into the container, I see that the file changes are propagated correctly. Yet, the server is not being restarted from within the container.

Trying the same thing outside a docker container works as expected. File changes trigger a restart with pm2-dev.

Branch releases on hub.docker.com

Not sure if those were present before the move, but right now the mentioned branches (0.12, 4) don't exist as Tags / Builds on hub.docker.com.

Can you quickly re-add those? Otherwise we would have to fork to get a running 0.12 build. And on a more general note: Is docker-volume meant as a 1:1 replacement for pm2-docker-alpine? Wasn't able to find any documentation / info on the move, but maybe I'm just not looking at the right places? I'm just asking, because I saw no further mention in this repository about passing the pm2-config file as an environment variable. Pretty sure that was possible before.

Would hate to be building upon this, when I can't be sure that it will provide some form of stability in the future. Suppose we built upon pm2-docker-alpine, and our infrastructure expected for those environment variables to work, we would, potentially, be in a lot of trouble right now. Would love to mitigate that risk by knowing the plan / future for this repository / organisation.

Start container as non-root user

First of all, thanks for the image. Following best practices I learned that it's best to not start containers as a root user.

When I switch to the node user though, I get "permission denied" error:

Error: EACCES: permission denied, open '/usr/local/lib/node_modules/pm2/node_modules/array-unique/index.js'
    at Object.fs.openSync (fs.js:651:18)
    at Object.fs.readFileSync (fs.js:553:33)
    at Object.Module._extensions..js (module.js:579:20)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/pm2/node_modules/micromatch/lib/utils.js:13:16)
    at Module._compile (module.js:569:30)

Is there a way to start this container as non-root user, i.e. assuming user "node". When doing so, for what files and directories do I need to change ownership to that new user?

TypeError: OAuth2Strategy requires a clientID option

TypeError: OAuth2Strategy requires a clientID option

Build of image successfully, but when running the container this error shows up

2019-01-24T04:56:10: PM2 log: App [app:0] exited with code [1] via signal [SIGINT] 2019-01-24T04:56:10: PM2 log: Script /src/index.js had too many unstable restarts (16). Stopped. "errored" 2019-01-24T04:56:12: PM2 log: 0 application online, retry = 3 2019-01-24T04:56:14: PM2 log: 0 application online, retry = 2 2019-01-24T04:56:16: PM2 log: 0 application online, retry = 1 2019-01-24T04:56:18: PM2 log: 0 application online, retry = 0 2019-01-24T04:56:18: PM2 log: Stopping app:app id:0 2019-01-24T04:56:18: PM2 error: app=app id=0 does not have a pid 2019-01-24T04:56:18: PM2 log: PM2 successfully stopped

while without docker i'm able to run my node backend app without any errors. Any help

Embed v8-profiler into image

@simonepri what do you about adding v8-profiler module (via pm2 install v8-profiler) by default? It would allow to snapshot memory and run cpu profiling when needed

Tags

  • create a tag for a Docker image that can embed sources
  • create multiple tags for Node.js 0.12.x/4.x/6.x

oci runtime error: container_linux.go:247

**Error: **

ubuntu@ip-172-18-16-104:~$ sudo docker run -it keymetrics/pm2 /bin/bash
Unable to find image 'keymetrics/pm2:latest' locally
latest: Pulling from keymetrics/pm2
1160f4abea84: Pull complete
3ec5cae38735: Pull complete
8936ea0e8ba7: Pull complete
bb97665bd848: Pull complete
Digest: sha256:ebc9a08b9f6181ac876ac9153523911eac163177cb2e379950282118af4273c0
Status: Downloaded newer image for keymetrics/pm2:latest
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory".

I use the followed command:

sudo docker run -it keymetrics/pm2 /bin/bash

my system is : ubuntu 16

NPM Ignoring proxy configuration

When the container is running on a host that is behind a corporate proxy, setting the proxy variables in npm config does not force npm to use the proxy when running an npm install. EDIT I confirmed that the container is trying to bypass the proxy by inspecting my AWS VPC Flow Logs.

Dockerfile:

FROM keymetrics/pm2:latest
WORKDIR /usr/src/app

RUN export https_proxy=$http_proxy && \
        npm config set proxy $http_proxy && \
        npm config set https-proxy $http_proxy


COPY package.json .

RUN npm config list && npm install

COPY . .

CMD [ "pm2-docker", "start", "app.js" ]

Command:

docker built -t <tag> --build-arg http_proxy=$http_proxy

Result:

Step 1/7 : FROM keymetrics/pm2:latest
 ---> 51e4768f2252
Step 2/7 : WORKDIR /usr/src/app
 ---> Using cache
 ---> 89c5ceb1fb5b
Step 3/7 : RUN npm config set proxy $http_proxy &&      npm config set https-proxy $http_proxy
 ---> Running in c57684fe32d5

 ---> c639679ae203
Removing intermediate container c57684fe32d5
Step 4/7 : COPY package.json .
 ---> 766ae6d99f23
Removing intermediate container 0264b7efe319
Step 5/7 : RUN npm config list && npm install
 ---> Running in 96f5f3e23d88

; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.5.1 node/v9.3.0 linux x64"

; userconfig /root/.npmrc
https-proxy = "10.202.1.215:3128"
proxy = "10.202.1.215:3128"

; node bin location = /usr/local/bin/node
; cwd = /usr/src/app
; HOME = /root
; "npm config ls -l" to show all defaults.

npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! network request to https://registry.npmjs.org/ip failed, reason: connect ETIMEDOUT 151.101.200.162:443
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-04-10T14_54_48_596Z-debug.log

node_args are not passed to the interpreter

I'm trying to enable remote debugging on my container but docker-pm2 is not passing the interpreter args to the interpreter:

/app # pm2 show ux
 Describing process with id 0 - name ux
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ status            β”‚ online                   β”‚
β”‚ name              β”‚ ux                       β”‚
β”‚ restarts          β”‚ 0                        β”‚
β”‚ uptime            β”‚ 6m                       β”‚
β”‚ script path       β”‚ /opt/ux/index.js         β”‚
β”‚ script args       β”‚ N/A                      β”‚
β”‚ error log path    β”‚ /dev/stderr              β”‚
β”‚ out log path      β”‚ /dev/stdout              β”‚
β”‚ pid path          β”‚ /tmp/ux_pm2-0.pid        β”‚
β”‚ interpreter       β”‚ node                     β”‚
β”‚ interpreter args  β”‚ --inspect                β”‚ --debug=5859 β”‚
β”‚ script id         β”‚ 0                        β”‚
β”‚ exec cwd          β”‚ /app                     β”‚
β”‚ exec mode         β”‚ cluster_mode             β”‚
β”‚ node.js version   β”‚ 9.0.0                    β”‚
β”‚ watch & reload    β”‚ ✘                        β”‚
β”‚ unstable restarts β”‚ 0                        β”‚
β”‚ created at        β”‚ 2017-11-04T16:31:14.627Z β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 Code metrics value
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Loop delay β”‚ 27.81ms β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 Add your own code metrics: http://bit.ly/code-metrics
 Use `pm2 logs ux [--lines 1000]` to display logs
 Use `pm2 monit` to monitor CPU and Memory usage ux
/app # pm2 monit
/app # ps
PID   USER     TIME   COMMAND
    1 root       0:01 node /usr/local/bin/pm2-docker start /opt/pm2.json
   22 root       0:01 PM2 v2.7.2: God Daemon (/root/.pm2)
   28 root       0:04 node /opt/ux/index.js
   48 root       0:00 /bin/sh
   84 root       0:00 ps

as you can see on the output of ps, node is not getting the extra args.

Drop dumb-init

dumb-init is useless with pm2 if the Dockerfile starts pm2-docker directly without using a bash script

-i # does not start cluster mode!

Trying to run my nodejs app with pm2 in cluster mode. The app works fine with:
CMD ["pm2", "start", "yarn start", "--no-daemon"] start 1 instance in fork_mode

But with:
CMD ["pm2", "start", "yarn start", "-i", "10", "--no-daemon"] 10 instances are started, yet still in fork_mode and I get errors regarding ports being already in use. How to force cluster mode? Is there an argument I'm missing?

PM2 don't stop with web API

Hi Folks,

By default a container exits when all applications have been stopped, but if you have enabled the web API and your application has crashed, the container keeps running because web API is on.

pm2-runtime start ecosystem.config.js --web

image

image

Anyone have any idea how can I fix it?

ty

Dockerfile does not build

$ sudo docker build .
Sending build context to Docker daemon 11.78 kB
Step 1/8 : FROM keymetrics/pm2:{{tag}}
Error parsing reference: "keymetrics/pm2:{{tag}}" is not a valid repository/tag: invalid reference format

Docker image: keymetrics/pm2:latest-alpine stopped working.

I see an update on 10th of December(today) on your Docker Hub at around 09:00 AM with ET.
And after this update containers based on your image stopped working.

When containers try to start I see such error:
internal/modules/cjs/loader.js:605
throw err;
^

Error: Cannot find module './add_days/index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
at Function.Module._load (internal/modules/cjs/loader.js:529:25)
at Module.require (internal/modules/cjs/loader.js:659:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object. (/usr/local/lib/node_modules/pm2/node_modules/date-fns/index.js:2:12)
at Module._compile (internal/modules/cjs/loader.js:723:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)

On docker push to aws - Retrying Issue

I tried
keymetrics/pm2-docker-alpine:latest
keymetrics/pm2-docker-alpine:8
and i got stacked on retrying issue on one layer at push.

ff22e6fe92fd: Layer already exists
401f4feac7bf: Layer already exists
213b10890d0a: Layer already exists
f4eb3bea93a9: Layer already exists
8ea9b7d8a6de: Pushing [======>                                            ]  3.645MB/26.49MB
1f3d81dffe31: Layer already exists
ac2baf0eaa8a: Layer already exists
5bef08742407: Layer already exists

when i tried
keymetrics/pm2-docker-alpine:7 it pushed with success!

Is this aws bug or runtime's?

Can't find Python executable "python"

env: mac osx

Some package will be dependent on python when gyp rebulid , for example canvas it will throw python not found but official docker images does not include such as python/g++ ... ... . it must be manually add or build in Dockerfile?

> [email protected] install /app/node_modules/canvas
> node-gyp rebuild

gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp ERR! configure error 
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.

Tutorial

Is there tutorial anywhere that demonstrates how to apply these tools?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.