Setting Up Your Development Environment with Docker Compose
blog.dubizzle.com
blog.dubizzle.com
services:
volumes:
- /path/to/my/code/on/my/dev/machine:/path/to/the/code/in/the/container
If you're sharing your docker-compose.yml file with other developers, this will get annoying really quickly. Normally, I'd place the docker-compose.yml file in the root of my project, and then replace "/path/to/my/code/on/my/dev/machine" with ".". That way, it doesn't matter where other devs keep code on their machines.In the case where you have a compose file that builds multiple projects (See: double time!), keep the compose file in one git repo, and then include the code for the other two projects (webappone and webapptwo) as submodules.
This is the part I find unacceptable for a development environment. Is there a way to have live-reloading of docker instance somehow?
This has been one of the great challenges for me. Nothing seems to work well with volume mapping.
We currently just don't mount node_modules at all, and run npm install when we build the image, and have to re-build whenever we change package.json. It sounds bad, but once we've got something working we tend not to need to add new dependencies, it's normally just code changes from there on out.
As an example, here's a docker compose for one service:
ports:
- "20003:20003"
volumes:
- ./APP/src:/opt/app/src
- ./APP/test:/opt/app/test
command: npm run dev
`run dev` is the thing that calls nodemon, which reloads whenever src or test change. Otherwise, everything like node_modules exists inside the image.`rerun --background -- "foreman start"`
It is super simple and works well for us
I think restarting an entire container for such small-scale changes is a bit much. Personally, I often resort to using a development server on the active project most of the time, it's a dirty solution with the consequence being that I've negated some of the advantages of my setup - if your server software is fast at restarting, you could throw in some sort of watcher.
Even more unrelated: it's written in Nim, and a big refactor is coming along that works with the Docker socket directly (either the AF_UNIX or TCP socket, depending on what's available)
For example, PyCharm supports using Docker Machine but not the new Docker for Mac. This means you won't necessarily have access to PyCharm's code inspection and remote debugging if you solely use Docker. This has resulted in my having a virtualenv on my host machine as well as the Docker setup, which is not ideal.
Once the tooling is better, things will be great; however, we aren't quite there yet.
One thing to note is that volumes can act weird at times if using docker-toolbox (I know the Blog Post was about using a Linux host).
https://www.virtualbox.org/ticket/14920
As a workaround we set up an alias for opening the file in VIM and saving it (without making any changes) that would run from within the container. Like the following:
vim <filename> -c 'wq!'Keep in mind that your environment variables can be learned by inspecting the image. So if you make that image public, those envs are visible. As far as i understand, this is analogous to committing your passwords to source control and should be a consideration.
Environment files are—unless I'm missing something—a run-time consideration. You provide the an env-file you have locally to connect to your development images, etc., and could deploy (possibly) the same image elsewhere, with a different env-file. But the env-file values are not baked into the image.
My dev env is deteriorating after 2 years use and I'll set up a new one this weekend.
Probably going to use NixOS, but also looking into Docker.
I'll post about it once I've ironed out a few more quirks. It makes life so much less unpleasant in so many ways.
[1] yeah we'll see how that goes