Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker not updating changes in directory

I am new in docker and i am trying to test a node server

Dockerfile

FROM node:8

WORKDIR /home/test-ci-node
COPY . .
EXPOSE 8080
CMD [ "node", "server.js" ]

server.js

var http = require('http');

//create a server object:
http.createServer(function (req, res) {
    console.log("got req");
    res.write('Hello World'); //write a response to the client
    res.end(); //end the response
}).listen(8080); //the server object listens on port 8080

console.log("listining at 8080");

and i started my docker image with command

docker run -p 8080:8080 -d docker_img

now in server.js i changed the response to

res.write('Hello World changed!');

and then i tried to restart container but changes were not reflected, i tried few google methods but results were same.

for changes to reflect i had to rebuild the image.

so is there a right way to reflect changes without rebuilding the image.

like image 594
Rohit Singh Avatar asked Oct 01 '18 10:10

Rohit Singh


1 Answers

In your docker file, you are using

COPY . .

This mean that, when you build your docker, you copy your current folder to the default folder of your container. Probably /root

But this copy isn't executed every time you RUN the container or START it, it's only when you BUILD.

To be able to see every change you make in real time without re BUILD, you need to create a volume, wich will be a link between your host and your container. Every content changing on the host or the container will be shared to the other.

Note that in your dockerfile, declaring a VOLUME won't actually change anything, it's just an information. To actually make a volume you need to add -v /host/path:/container/path in your docker run command line.

like image 80
Artandor Avatar answered Sep 18 '22 06:09

Artandor