Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reflecting code changes in docker containers

Tags:

docker

express

I have a basic hello world Node application written on express. I have just dockerised this application by creating a basic dockerfile in the applications root directory. I created a docker image, and then ran that image to run it in a running container

# Dockerfile
FROM node:0.10-onbuild
RUN npm install
EXPOSE 3000
CMD ["node", "./bin/www"]

sudo docker build -t docker-express
sudo docker run --name test-container -d -p 80:3000 docker-express

I can access the web application. My question is.. When I made code changes to my application, eg change 'hello world' to 'hello bob', my changes are not reflected within the running container.

What is a good development workflow to update changes in the container? Surely I shouldn't have to delete and rebuild the images after each change?

Thank you :)

like image 347
Toby Avatar asked Apr 10 '15 17:04

Toby


People also ask

How do I reflect changes in docker container?

So mirroring files to Docker containers will reflect all changes in the container. The npm run build:watch from the application will catch the changes and generate output files in the lib folder so the npm run dev:run will restart the server every time it has been triggered.

Are changes in docker container saved?

Hence, if you want the changes to persist, you can use the Docker commit command. The commit command will save any changes you make to the container and create a new image layer on top of it.

How do I change the code in running docker container?

Navigate to the directory you'd like to open and press “OK”. The sidebar will update to display the selected directory's contents. Click any of the files to open it in the VS Code editor. You can now make changes inside the container, without manually copying files or setting up a working directory bind mount.

Which command is used to inspect changes on a container file system?

Using Docker Diff The Docker CLI has a built-in command for this purpose. Running docker diff will enumerate all the changes made to files and directories within a particular container. It accepts the ID or name of the container you want to inspect.


1 Answers

Check out the section on Sharing Volumes. You should be able to share your host volume with the docker container and then any time you need a change you can just restart the server (or have something restart it for you!).

Your command would look something like: sudo docker run -v /src/webapp:/webapp --name test-container -d -p 80:3000 docker-express

Which mounts /src/webapp (on the host) to /webapp (in the container).

like image 71
Brennan Avatar answered Oct 24 '22 22:10

Brennan