Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodemon inside docker container

I'm trying to use nodemon inside docker container:

Dockerfile

FROM node:carbon
RUN npm install -g nodemon
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "nodemon" ]

Build/Run command

docker build -t tag/apt .
docker run -p 49160:8080 -v /local/path/to/apt:/usr/src/app -d tag/apt

Attaching a local volume to the container to watch for changes in code, results in some override and nodemon complains that can't find node modules (any of them). How can I solve this?

like image 696
Jumpa Avatar asked Jan 18 '18 16:01

Jumpa


1 Answers

In a Javascript or a Nodejs application when we bind src file using bind volume in a Docker container either using docker command or docker-compose we end up overriding node_modules folder. To overcome this issue you need to use anonymous volume. In an anonymous volume, we provide only the destination folder path as compared to the bind volume where we specify source:destination folder path.

General syntax

--volume <container file system directory absolute path>:<read write access>

An example docker run command

docker container run \
    --rm \
    --detach \
    --publish 3000:3000 \
    --name hello-dock-dev \
    --volume $(pwd):/home/node/app \
    --volume /home/node/app/node_modules \
    hello-dock:dev

For further reference you check this handbook by Farhan Hasin Chowdhury

like image 57
Arpit Jain Avatar answered Oct 06 '22 01:10

Arpit Jain