What is the process for modifying code within a Docker Container?

My Docker and Containers knowledge is very limited, along with understanding VM concepts as a whole.

I grasp the idea that VMs and Dockers help package all application dependencies into a single component for easy deployment on compatible cloud platforms.

After installing Docker on my local Ubuntu machine, I followed this guide to run the Node Official Image.

Now, my question is: how do I update code changes within Docker? I edited 'server.js' in the app, but even after restarting the container, the browser displays the old output at http://locahost:49160. Is creating a new image the only solution, rendering the old one useless?

Perhaps I'm missing something fundamental about how Docker operates?

Answer №1

In order to modify the contents within a container, you have the option to save these changes to the original image or create a new one altogether.

It is advisable to opt for creating new images or tags when making modifications.

Refer to this helpful guide. If you need to alter the server.js, go ahead but remember to build a fresh image with a corresponding tag (test1).

For instance, use

docker build -t <your username>/node-web-app:test1 .

Afterwards, execute the new image using

docker run -p 49160:8080 -d <your username>/node-web-app:test1

Answer №2

If you find yourself in a similar situation, rebuilding your image may be necessary:

docker build -t my-new-image .

If changes have been made to your server.js file and it's included in your image/container, the old image will no longer serve its purpose. Starting a new container with docker run will be required after the rebuild.

In certain scenarios, it is feasible to link your code/data to your docker container using

docker run -v my-local-volume:/volume-in container ...

To automatically update the code within your container when edits are made on your local machine without having to update the image or restart the container, you can implement this method. However, if you're manually copying the code inside your application using the COPY command from the dockerfile as in this case, a rebuild may be necessary.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Converting PPT files to PDF or PNG using Node.js

Are there any options available for converting ppt files to pdf or png without relying on specific operating system dependencies? I need to convert a ppt file to png, but all the current packages I have tried require tools like LibreOffice or ImageMagick ...

Locating a Guild Member using their Alias

I need help locating a GuildMember using their nickname. The nickname is linked to their Roblox name upon joining the server, and I've configured a webhook to transmit a message in a specific channel containing their username and other related details ...

Error encountered when attempting to reference multiple Select MenuItems in Material UI

Recently, I've been encountering a perplexing error when attempting to open a multiple Select in React+Next.js using Material UI: Error: Argument appears to not be a ReactComponent. Keys: retry This issue seems to be related to a ref. It occurs with ...

Exploring the Possibilities with NodeJS and Socket.IO

I've encountered an interesting issue with my use of NodeJS and Socket.io. The server receives data through ZeroMQ, which is working perfectly fine. However, when there are a large number of connected clients (over 100), it appears that there is a de ...

The error message "chai TypeError: util.addProperty is not a function" appears when starting the express.js backend using the 'npm start' command

I've exhausted all my known methods to address the ongoing issue, but unfortunately, I haven't been able to resolve it. Therefore, I'm reaching out for your valuable advice. Thank you in advance. Everything was working fine with the app unt ...

Dividing a TypeScript NPM package into separate files while keeping internal components secure

I have developed an NPM package using TypeScript specifically for Node.js applications. The challenge I am facing is that my classes contain internal methods that should not be accessible outside of the package, yet I can't mark them as private since ...

The newest version of Express, 4.0.0, comes with outdated dependencies and security

After installing the default versions from the Ubuntu 18.04 LTS repositories: nvm 0.35.0 node v10.16.3 npm 6.9.0 express 4.0.0 When trying out commands from various sources like the express starter tutorial, StackOverflow, and blogs, express app --view= ...

Nodejs is encountering an error while attempting to refresh pages, resulting in the inability

I recently completed a website, and I've noticed an issue where the home page refreshes just fine, but when I navigate to other pages and hit refresh, I encounter this error: Cannot GET /otherpage The website is built using react-navigation, and I su ...

Answer processing for the reminder dialog is underway

When I send a proactive message to a user, I want to initiate a 'reminder dialog'. The dialog is displayed, but when processing the response it goes back to the main dialog. This is how I currently set up my bot: const conversationState = new C ...

The scss file attached to the Express JS pug files is rendering the styling in the email as plain text

I am currently attempting to include a stylesheet file in a .pug template that will be sent via email: head link(rel='stylesheet' href='../../assets/stylesheets/style.css' type='text/css') .flex.border div img.bann ...

When trying to install Angular 6 locally, I encountered an issue with Angular 10 where the package.json file was being ignored

Recently, I encountered an issue with my Angular project. I have a project based on Angular 6.0.7 which I pulled from our repository. On a global level, I have Angular 10.0.4 installed. Despite having the correct version specified in my package.json file, ...

Guide on integrating npm packages with ASP.NET CORE 2 in Visual Studio 2017

After incorporating several npm packages into my ASP.NET Core 2 project in Visual Studio 2017, I encountered an issue where the css and js files from these packages were not being recognized by VS. This was likely due to the node_modules folder being locat ...

The callback function for ExpressJS Passport OIDC integration is not triggering as expected

I'm a beginner when it comes to the authentication system or OIDC. Currently, I am in the process of integrating an OIDC tool known as CILogon () into a website that I'm constructing. Essentially, this tool can redirect a user to a third-party lo ...

Node.js Express is running into issues with verifying the integrity of Shopify webhooks

After referring to the code snippet provided here I encountered an error message that read: Unhandled promise rejection (rejection id: 2): TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object To address this issue, ...

The NPM start script executes successfully in a local shell, but encounters errors when run within a Docker container

I have a Node application with three separate Node servers running using pm2 start. To start all three servers concurrently, I am using concurrently in my package.json file: "scripts": { ... "start-all": "concurrently \" pm2 start ./dist/foo. ...

Can't seem to res.send using Express framework

Hello, I'm encountering an issue when trying to send a response using Express. I've seen suggestions in other questions that changing the variables err and res may resolve this problem, but it hasn't worked for me. router.post('/checkP ...

Transferring binary information from C++ to Node.js

I have a binary data stored in a C++ variable called buffer. Here is the code snippet: int len = 39767; uint16_t * buffer = (uint16_t) malloc(len); FILE * fp = fopen("rahul.jpg", "rb"); // file size is 39767 bytes. fread(buffer, len, 1, fp); fclose(fp); f ...

Solve the mystery of hidden IP addresses in Node.js with the help of the DNS module

Is it possible to achieve the same result as running the command dns-sd -q a5b3ef18-2e66-4e24-91d2-893b93bbc1c1.local on Mac OSX using Node.js? It appears that the dns module in Node.js is primarily used for converting website addresses to IP addresses, no ...

Recursive function in JavaScript with error handling using try-catch block

Within my nodejs script, I have implemented a system to generate dynamic tables and views based on the temperature data recorded for the day. On some occasions, the creation of these tables is hindered if the temperature falls outside of the normal range ...

struggling to send variables to jade templates with coffeescript and express.js

As a newcomer to node and express, I am currently building the front end of an application that utilizes jade as its templating engine. Despite extensive searching online and within this community, I have not been able to find a solution to a particular is ...