Last active
September 30, 2020 17:27
-
-
Save fbarriga/ad3de2c2dd4064b0ffc6b9af2fd8116f to your computer and use it in GitHub Desktop.
NodeJS Development using docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "docker_web_app", | |
"version": "1.0.0", | |
"description": "Node.js on Docker", | |
"author": "First Last <first.last@example.com>", | |
"main": "server.js", | |
"scripts": { | |
"start": "node server.js" | |
}, | |
"dependencies": { | |
"express": "^4.13.3", | |
"nodemon": "^1.8.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
getent group -i $GID | |
if [ "$?" -ne "0" ]; then | |
echo "Group with the same GID not found, adding group" | |
groupadd -r -g $GID $GROUP | |
fi | |
id -u $_UID | |
if [ "$?" -ne "0" ]; then | |
echo "User with the same UID not found, adding user" | |
useradd -r -g $_UID $USER | |
fi | |
_USER=`id -u $_UID -n` | |
# for some reason isn't working... | |
su - "$_USER" | |
whoami | |
cd /app | |
npm install | |
./node_modules/nodemon/bin/nodemon.js --legacy-watch server.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# http://paislee.io/the-ultimate-nodejs-development-setup-with-docker/ | |
# execute with: | |
# ./scripts/development.sh . | |
CONTAINER_NAME=fbarriga_node_dev | |
IMAGE=node:7.7.1 | |
LOCAL_PORT=8080 | |
CONTAINER_PORT=8080 | |
_UID=`id -u ${USER}` | |
GID=`id -g ${USER}` | |
GROUP=`id -g -n ${USER}` | |
docker stop ${CONTAINER_NAME} | |
docker rm ${CONTAINER_NAME} | |
docker run -d -p ${LOCAL_PORT}:${CONTAINER_PORT} \ | |
--name ${CONTAINER_NAME} \ | |
-e "USER=${USER}" \ | |
-e "GROUP=${GROUP}" \ | |
-e "_UID=${_UID}" \ | |
-e "GID=${GID}" \ | |
-e "NODE_ENV=development" \ | |
-v `pwd`:/app ${IMAGE} \ | |
/app/scripts/dev_entrypoint.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const express = require('express'); | |
// Constants | |
const PORT = 8080; | |
// App | |
const app = express(); | |
app.get('/', function (req, res) { | |
res.send('Hello world\n'); | |
}); | |
app.listen(PORT); | |
console.log('Running on http://localhost:' + PORT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment