Run Docker Container (with node.js 7.4.0)

Prepared containers with node:
https://hub.docker.com/_/node/

Scripts for create Docker container:
https://github.com/nodejs/docker-node/

Step1: download prepared container

$ docker pull node


Step 2: Create and Run Docker Container

$ mkdir ~/projects
$ project_name=<my_project_name>


$ echo ${project_name}


$ mkdir -p ~/projects/${project_name}


$ cd ~/projects/${project_name}


// For Example:
$ git clone https://github.com/marley-react/The-Complete-React-Web-App-Developer-Course .

and now you can work with this project with any editor.


$ docker run -it \
-p 80:8080 -p 1337:1337 -p 3000:3000 -p 4000:4000 -p 5000:5000 -p 6000:6000 -p 7000:7000 -p 8000:8000 -p 9000:9000 \
--name ${project_name} \
-v ~/projects/${project_name}:/project \
node \
/bin/bash


# node -v
v8.2.1


# npm -v
5.3.0


# apt-get -qq update

# apt-get install -y vim curl net-tools

net-tools contains ifconfig


create user without additional questions:


# adduser --disabled-password --gecos "" developer
# chown -R developer /project/


# su - developer
$ cd /project/


And as result, we can work with project on local computer and run project in docker container. In docker container project locate in /project folder.


Almost the same but with Dockerfile


Dockerfile


FROM node:latest

RUN apt-get update
RUN apt-get install -y vim git

RUN mkdir -p /project /home/nodejs && \
    groupadd -r nodejs && \
    useradd -r -g nodejs -d /home/nodejs -s /sbin/nologin nodejs && \
    chown -R nodejs:nodejs /home/nodejs

WORKDIR /project
COPY . /project

RUN chown -R nodejs:nodejs /project

USER nodejs
CMD ["bash"]


# docker build -t myProject .
# docker run -it --rm -p 3000:3000 -p 3001:3001 myProject