All code from this tutorial as a complete package is available in this repository. If you find this tutorial helpful, please share it with your fr...
For further actions, you may consider blocking this person and/or reporting abuse
Awesome article Alex! It really helped me on a very specific case :)
nice post! how to persist postgres data between container restarts?
you need volumes, this section should help answer:
dev.to/alexeagleson/docker-for-jav...
Will try this out
OMG! I should follow you for more quality content. Thank you Alex
You're so Great
Excellent tutorial, Alex! After a few years of having no interest in understanding containers, this tutorial finally explained their practical use coupled with a good example and now I want to learn more!
I have been trying to follow the example in the tutorial, but I'm having an issue. Basically, I opted not to install NPM on the host machine and want to have NPM only installed in the container. When I run the sample without the volume, everything works fine and I can access the Hello World web page, i.e. this works:
docker run -p 3000:8080 --name my-node-app-container my-node-app
However, when I try to run the sample with the volume "mapping", then the command fails, i.e. this does NOT work:
docker run -p 3000:8080 --name my-node-app-container --volume ${PWD}:/usr/src/app my-node-app
This is the output:
PS C:\docker-template> docker run -p 3000:8080 --name my-node-app-container --volume ${PWD}:/usr/src/app my-node-app
> server@1.0.0 start /usr/src/app
> nodemon server.js
sh: nodemon: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! server@1.0.0 start:
nodemon server.js
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the server@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-01-03T09_07_28_520Z-debug.log
What puzzles me is the "but node_modules missing, did you mean to install" message? Does this mean that since I am syncing my local host folder with the working folder in the container that the syncing ends up overwriting the potentially already built "node_modules" folder and hence it's missing? As mentioned, my local host folder (C:\docker-template) does not have node_modules because I opted not to install NPM on the host and was hoping to get away with NPM only in the container.
I am running Docker on Windows via Docker for Desktop and on WSL2. My C:\docker-template folder contains only 3 files: Dockerfile, package.json and server.js.
You bring up a good point there is an issue here when you don't have a
node_modules
directory in the source. Basically the "lack of the directory" gets overwritten on the volume mount.Here is a stackoverflow discussion about the issue:
stackoverflow.com/a/32785014
It talks about it in the context of
docker-compose
but the same principle should apply without compose. The syntax for adding the additional volume would be:Fantastic tutorial, Alex! I've tried several times to understand the various Docker concepts and why I'd want to use particular things like volumes and Docker Compose. It all became clear with your explanation. I really appreciate your effort and, especially, how you went step by step! Thank you!
That's the best result I could hope for, thank you for sharing your experience.
This article is SO AWESOME!
Cheers friend.
Obrigado pela ótima explicação.
From Brazil
Thanks You Alex.
Hi Alex, Thanks for this great tutorial. But I’m getting an error after runinng "docker-compose up --build" attached below:
"Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Attaching to for-interview-app-1, for-interview-postgres-1
Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:5432 -> 0.0.0.0:0: listen tcp 0.0.0.0:5432: bind: address already in use".
Could you please help me here?
Very much needed introduction in the front-end/JS world! Great job :)
Glad you enjoyed it. It's a really fantastic tool.
Worth reading as a beginner. Thanks Alex!