Lightweight docker image based on Alpine with nodejs environment inside.
| Alpine | NodeJS |
|---|---|
| v3.11 | v14.4 |
Also, the image contains npm, npx and yarn.
Create "Hello world example" using ExpressJS.
# create example directory
mkdir hello_world_project
# go to created directory
cd hello_world_project
# create file contains a javascript code
touch index.js
Content of index.js:
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
Create nodejs docker environment:
# load docker image from hub.docker.com
docker pull sbovyrin/nodejs
# create docker container from loaded image
docker run --name nodejs -v $PWD:/home/node/app -p 3000:3000 -d sbovyrin/nodejs
# run "npm init -y" command within created container
docker exec -it nodejs npm init -y
# run "npm install express --save" command within created container
docker exec -it nodejs npm install express --save
# run "node index.js" command within created container
docker exec -it nodejs node index.js
Now, you will see Example app listening on port 3000! in your console.
Open your browser and go to localhost:3000. You should see Hello World!.
docker pull sbovyrin/nodejs
docker run --name nodejs -d sbovyrin/nodejs
docker exec -it nodejs <your_command>
docker exec -it nodejs sh
Content type
Image
Digest
Size
47 MB
Last updated
over 6 years ago
docker pull sbovyrin/nodejs