DEV Community

Cover image for Say Goodbye to Docker Volumes 👋

Say Goodbye to Docker Volumes 👋

Jonas Scholz on November 27, 2023

Ever tried to use Docker volumes for hot-reloading in your web app? If you had the same horrible experience as me, you will enjoy the newest featur...
Collapse
 
patroza profile image
Patrick Roza

Hard to believe there are people out there developing their apps in containers.
I would personally say goodbye to Docker (for developing) instead.

Collapse
 
cavo789 profile image
Christophe Avonture

For me there is today no other ways than using Docker containers. I'm working in a team and since I've introduced docker the " it doesn't work on my machine" didn't exists anymore.

And since all settings are in docker, a new colleague just need to run a very few commands and he can start to code.

I'll no more work like previously. Docker all the time for me.

Collapse
 
patroza profile image
Patrick Roza

This can be achieved without Docker via env managers, nix, or even just smart setup. When settings can live in docker files they can also live elsewhere

Thread Thread
 
cavo789 profile image
Christophe Avonture

Sorry I disagree. Using Docker I can create my own Docker images where I can foresee everything like, for PHP, each PHP modules to load, how they should be configured and so on. Then just give my docker-compose.yml file (and associated Dockerfile files) so everyone has the perfect setup.

Everything correctly configured, everyone using the same versions of tools and when I'll update f.i. php from 8.2 to 8.3 it'll be done for everyone at no cost. I'll make the change and everyone will get the newer version with no effort.

Docker has totally change how we're working.

Thread Thread
 
patroza profile image
Patrick Roza • Edited

I can see this is more complicated with stacks like that. Still you don’t need Docker for that. Nix will do that just fine for you, without containers. Now I’m personally not a huge fan of nix, but there are others too, it’s not limited to containers.
Docker is great for distribution, deployment, testing, having requirements to run many things together, but for a little bit of environment, setting and package management it’s like using an elephant to catch a mouse :)
With all complexion and issues like watchers and networking involved. Especially on non native systems like Mac and Windows.

That said, if it works for you/team, then it is hard to argue. It is the most important factor.

Thread Thread
 
cavo789 profile image
Christophe Avonture

Here too, I didn't agree since, under Windows, we can use WSL2 (Windows Subsystem for Linux).

I should admit I don't even what Nix is (and I'm not really curious about since Docker fullfill my needs right now).

We (my team) are using Docker on Windows machines, in a WSL2 environment. We're coding a major PHP application with a lot of dependencies, we've a backend, an api, a front using VueJS3, we've PostgreSQL and MySQL db, ... and everything is configured using Dockerfiles and a few docker-compose.yml ones.

Our projects are stored in our, self hosted, Gitlab environenment and all actions are available using a makefile so, when someone need to do something (like running pgadmin for instance), he didn't to remember which command to ... it's just make something like, here, make pgadmin.

All the complexity have been swallowed up by one member of the team, in charge of the maintenance of the framework and the others just enjoy by running very easy make something commands.

Yes, learning Docker is not easy but yes, I would never go back for local development. Everyone has the same installation, no more "it didn't work on my machine", etc.

Collapse
 
rslhdyt profile image
Risal Hidayat

I just discovered this docker compose watch things. However, I have two services that share the same code base (web and workers). Using docker compose watch makes infinite build and sync issues. because bot services are updating each other. I think I will stick to the volumes until I can figure out that issue :(

Collapse
 
code42cate profile image
Jonas Scholz

Oh interesting, didnt even consider that this might be the case. Thanks for sharing!

Collapse
 
paulrobello profile image
Paul Robello

Docker for my team is a lifesaver. When you have developers running on Windows, Linux, Mac, x86 / arm architectures. The emulation provided by doctor as well as the ability to package the needed binaries and environments is a must. Many projects have many dependencies that you don’t want to pollute your development machine with. Or cause cross contamination between different projects. I personally have had great success, using host volumes to mount my code into a container for real time changes both inside and outside of the container. I have created a pretty robust docker dev tool GDC

linked in article

Collapse
 
code42cate profile image
Jonas Scholz

What is your 2 sentence pitch for GDC? I'm having a hard time exactly understanding what it does from the GitHub README 👀

Collapse
 
paulrobello profile image
Paul Robello • Edited

My Linked in post in the article sums it up in a bit more than 2 sentences, but let me see if I can condense it a bit more.
At its core It is an IDE agnostic tool which allows you run your IDE locally to edit / debug code that runs inside a container. The GDC works with Windows / Mac / Linux, x86 / arm and many popular languages such as JS/TS, Python, Java, Dot Net, PHP etc.

Collapse
 
wintercounter profile image
wintercounter

Let's store node_modules twice on our machines!

Jokes aside, it's nice to have, but I'll probably still stick to volumes, especially on large projects. I can't see how any watcher can be sufficient enough on large codebases. There's a reason all tools exclude 3rd party lib folders, like node_modules from their watchers.

Collapse
 
code42cate profile image
Jonas Scholz

node_modules are excluded from the watch if they are in .gitignore :)

Collapse
 
wintercounter profile image
wintercounter

So that's even worse, because I need to install both places anyway to make the IDE work.

Thread Thread
 
code42cate profile image
Jonas Scholz

Well sure, but with a fast internet connection and enough disk space that isn't really a concern for me luckily:)

Thread Thread
 
wintercounter profile image
wintercounter

Well, enough is quite relative. I have 4TB+ SSD RAID and soon I need to extend again. 60% of space are node_modules :D

Thread Thread
 
code42cate profile image
Jonas Scholz

Lmao that is impressive

Collapse
 
proteusiq profile image
Prayson Wilfred Daniel

I have been waiting for this for a long time. When teaching Machine Learning, I have opted to use containers to avoid time wasted installing tools on students' PCs.

I disliked mounting, as it was not sufficient, and did not have restart and reinstallation. These will solve 70% of my issues when developing and teaching Python + ML.

Thank you for sharing 🙏🏾

Collapse
 
code42cate profile image
Jonas Scholz

Ohh thats so cool! Hope this works out for you:)

Collapse
 
corentingosselin profile image
Corentin Gosselin

Amazing new feature, thank you for sharing ! Your monorepo example is exactly my setup right now

Collapse
 
code42cate profile image
Jonas Scholz

Nice! I think it's one of the most productive setups I've ever had. Anything that you changed to make it even better? 👀

Collapse
 
corentingosselin profile image
Corentin Gosselin

I would not place the dockerfiles in root of the project. I usually place them inside their associated app path: like apps/frontend/my-app/docker/dockerfiles or /apps/backend/my-api/docker/dockerfiles. This way if you have multiple apps you keep it structured :)

Thread Thread
 
code42cate profile image
Jonas Scholz

Yeah, I used to do that as well but stopped for some very specific reason that I don't even remember anymore lol. At this point I'm just used to it and with less than 5 apps it's still manageable :)

Thread Thread
 
code42cate profile image
Jonas Scholz

I think some hosting platform I used didn't really support that when I started with monorepos? Really no reason to still do that I guess x)

Collapse
 
nicolkill profile image
Nicol Acosta

I personally work on personal and professional stuff with docker and this its gold to me, thanks

Collapse
 
matrixnh profile image
Nadir Hamid

Great read. This is definitely better than using volumes. They were a pain to manage and annoying to integrate with app workflows. Indeed, each framework has a unique set of development challenges and there is no one size fits all, but this new feature helps. It would be good to use some of these rebuild actions in case a basic watch procedure doesn't work.

I hope other dev teams find this soon as it can save them large amounts of time.

Collapse
 
jeremymoorecom profile image
Jeremy Moore

Thank you for sharing! Looks like most of my questions are answered in the docs.

Collapse
 
code42cate profile image
Jonas Scholz

Thanks :) Anything that you think I missed that I should've included?

Collapse
 
flyingcodemonkeys profile image
flyingCodeMonkeys

so much hot sexy goodness! save me tons of headaches. holy cow this is good. 😀

Collapse
 
m0n0x41d profile image
Ivan Zakutnii

It is so neat, thank you for sharing this news!

Collapse
 
code42cate profile image
Jonas Scholz

Glad you liked it!

Collapse
 
pftg profile image
Paul Keen

Why do you need to add your code to the container? When would you need that instead of mount? I have not see dev containers with adding code to the image.

Collapse
 
pftg profile image
Paul Keen

You can find robust version to prevent hacks with watch here jtway.co/running-tests-in-containe...

Collapse
 
pradumnasaraf profile image
Pradumna Saraf

Compose watch is an amazing addition. There was always an issue with the hot reloading using volumes.

Collapse
 
eevargas profile image
Eli Vargas

I'm guessing volumes are a problem for non-Linux users. I have no issues with Docker volumes. But non-linux Docker actually runs on a VM. So I can see that could cause problems with hot reloads. 🤔 Good luck guys. 😅

Collapse
 
joolsmcfly profile image
Julien Dephix

Same here.
After reading the title I was wondering what was wrong with volumes but I'm running Ubuntu so that could be why I have no problems: yarn watch and code! ^_^

Collapse
 
namdevgg profile image
namdevgg

Goood

Collapse
 
cabrel92 profile image
cabrel92

Thanks for your Post.
Nowadays, Developer shall think of working with docker, I personally try to dockerise every application I work on. I have stopped working with vagrant for a while, because of ressources consumption, and many other things.
So for me docker is the most for Dev.
Nos that I can use watch ( sync/rebuild/ sync+), now that I have opportunity ti share my Container with colleagues, I feel more comfortable.

Collapse
 
anhvandev profile image
anhvandev

Hopefully there will be a feature to dispatch multiple commands after changing package settings :v it will look like a CD tool in the local environment.

Collapse
 
grigorkh profile image
Grigor Khachatryan

This news is quite impressive; Thanks for sharing it!

Collapse
 
code42cate profile image
Jonas Scholz

Glad that you enjoyed it!:)