-2

I'm wondering if it's possible to create some kind of docker container that will allow me and my friends to develop directly into container - without having node or it's dependency installed locally? Is it possible to develop like that and use git as well?

If it's possible, could you share a link where I could check how to do it with node apps?

Thanks!

susanoo
  • 289
  • 4
  • 13
  • you can mount your local directory contains code to container. you can look at this (question)[https://stackoverflow.com/questions/23439126/how-to-mount-host-directory-in-docker-container] – Bukharov Sergey Oct 24 '17 at 13:22

1 Answers1

0

You can build your image by installing all dependencies (node, npm, your packages) then copy your code inside and share your working directory, your entrypoint/cmd should run your node script.

Read this article which will help you understand how to build efficient dockerfile for node.js especially. You can also read this from docker's website for general best practices.

Here is a simple docker file to only give you a simple idea how to hookup your code and run simple html page in your machine inside nginx server inside container (you did not install nginx at all in your machine).

Note: this is only to understand the concept

1) Create a new file, name it dockerfile and add the following content, I tried to give you comments for each line to understand but you can remove those comments if you want.

FROM ubuntu #this is the base image
MAINTAINER Your name
RUN apt-get update #feel free to install and update packages 
RUN apt-get install -y nginx #easily as you're in your linux env, you can install nodejs here 
COPY . /usr/share/nginx/html/ #share the current content of working directory to nginx folder inside container
ENTRYPOINT [“/usr/sbin/nginx”,”-g”,”daemon off;”] #run nginx server that should display copied files 
EXPOSE 80 #expose port 80 to your machine (host) 

Notice COPY where we copied content of your code inside container.

2) Inside the same directory, add index.html and your content inside it

$ echo "hello world" > index.html 

3) Build your image and tag/name it MyImage

docker build -t MyImage:latest .

4) Run your container or instance of your image:

docker run -d -p 80:80 MyImage 

5) browse http://localhost

For more info. and details, better to check docker's documentation.

Muhammad Soliman
  • 21,644
  • 6
  • 109
  • 75