Alpine Docker Puppeteer Environment
473
$ docker pull leafney/alpine-puppeteer
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
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.
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'
}
}],
};
Copy all files in the node_app directory to the volume directory like /home/tiger/node_app and restart the container.
Enjoy it!
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
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)
Content type
Image
Digest
Size
155.7 MB
Last updated
about 7 years ago
docker pull leafney/alpine-puppeteer