Sign inSign up

leafney/alpine-puppeteer

By leafney

Updated about 7 years ago

Alpine Docker Puppeteer Environment

Image
0

473

leafney/alpine-puppeteer repository overview

alpine-puppeteer
Get Image from Docker Hub
$ docker pull leafney/alpine-puppeteer
Run a container for your nodejs app

The main directory of the project in the container is /app.

$ docker run --name puppet -d -p 8000:8000 -v /home/tiger/node_app:/app leafney/alpine-puppeteer:latest

If you set the log directory to /logs in the PM2 configuration file, you can do this:

$ docker run --name puppet -d -p 8000:8000 -v /home/tiger/node_app:/app -v /home/tiger/node_logs:/logs leafney/alpine-puppeteer:latest

Node App Demo
simplest Express application

Take a simplest Express application as an example. More: Express "Hello World" example

Create the project directory:

$ mkdir node_app

$ cd node_app

Use yarn to init:

$ yarn init

Install needed package express.

$ yarn add express

Create the main file of index.js in path /src.

const express = require('express')
const app = express()
const port = 8000

app.get('/', (req, res) => res.send('Nodejs App Running in Docker!'))

app.listen(port, () => console.log(`Example app listening on port ${port}!`))

The default port is 8000.

Run the app with the following command:

$ node src/index.js

Then, load http://localhost:8000/ in a browser to see the output.


Modify pm2 config file

The ecosystem.config.js is pm2 config file. You need to change the configuration items that have been applied to your project.

module.exports = {
  apps: [{
    name: 'node_app',
    script: './src/index.js',
    instances: 1,
    autorestart: true,
    watch: false,
    // watch: ["src"],
    // ignore_watch: ["node_modules"],
    max_memory_restart: '50M',
    log_date_format: 'YYYY-MM-DD HH:mm:ss',
    out_file: '/logs/puppet_out.log',
    error_file: '/logs/puppet_error.log',
    env: {
      NODE_ENV: 'development'
    },
    env_production: {
      NODE_ENV: 'production'
    }
  }],
};
Run

Copy all files in the node_app directory to the volume directory like /home/tiger/node_app and restart the container.

Enjoy it!


Change container timezone UTC to CST

If the container name is puppet,use command docker exec puppet utc2cst.sh to change:

$ docker exec puppet utc2cst.sh
[i] change timezone success
Mon Apr  8 01:52:13 CST 2019

$ docker restart puppet
puppet

show app status

use pm2 list or pm2 monit to get app status:

docker exec -it puppet pm2 list
# or:
docker exec -it puppet pm2 monit
# (use `q` exit)

Tag summary

Content type

Image

Digest

Size

155.7 MB

Last updated

about 7 years ago

docker pull leafney/alpine-puppeteer