Reputation: 4328
I'm completely new to Docker and Containers. I'm also new to the entire VM concepts.
I understand that VM and Dockers are a way to make all the dependencies of an application to be available as a single component that you can easily deploy on clouds that support them.
I installed Docker on my local machine (an Ubuntu) and I used used this guide to download and run the Node Official Image.
What I need to know now is how do I make code changes for the files inside of Docker? I made changes to the 'server.js' inside the app and when I navigate to http://locahost:49160
the browser still shows the output from the old server.js
. I restarted the container and yet I get the same old output.
I see that I can commit changes and make a new image. But then, isn't the old image completely useless?
Or am I not at all understanding how things with Docker work?
Upvotes: 10
Views: 10286
Reputation: 30841
In your case. You'll probably need to rebuild your image:
docker build -t my-new-image .
You made an edit to your server.js
which is copied inside your image/container. The old image will be useless indeed. You'll need to start a new container with docker run
after the build.
In some cases it's possible to mount your code/data to your docker container with docker run -v my-local-volume:/volume-in container ...
When you make edits to your code on your local machine it will be updated inside your container automatically. Without updating the image or restarting the container. But in your case your copying the code inside your application with the COPY
command of the dockerfile.
Upvotes: 3
Reputation: 2363
You could make changes inside an container and could even commit these changes to the original image or create a new image as well as.
But I recommend you to create a new images or tags.
Review the guide. When you want to make a change on server.js
, let do it but build a new image for it also. Don't forget to add a tag (test1
).
Example, docker build -t <your username>/node-web-app:test1 .
Then you could run the new image with docker run -p 49160:8080 -d <your username>/node-web-app:test1
Upvotes: 8