I am new to docker(2 days) and really trying to understand how I can integrate it in my development workflow.
Consider this situation (yes, I made this picture)
I am continuously working on my local git repo and want to test my code in one(or more) docker containers.
Question
a.) What is the best way recommended to get the code locally to these containers.
The reason I asked is because if I have to git commit-push locally and pull in respective containers, I see 2 problems upfront with that
1.) The rounds trip time in development is costly
2.) What if I am not in state to check-in my code, I am just testing/reproducing a bug etc.
Pardon my ignorance and please enlighten me with your ideas
Thanks
For (2), that's what Git branches are for. If (1) is really a deal-breaker, and if Docker is running on the same machine that you're doing your development on (it's not clear whether that's the case), you can mount the local directory containing your code into a new Docker container with:
docker run -v /local/path/to/code:/path/inside/container/where/code/will/be --other-options imagename
This way, the directory will exist on both your local machine and in the Docker container at the same time (with changes at either end automatically showing up in the other), and you can operate on the directory's contents directly within Docker.
Docker maintain a number of official language images that can be used to build containers from your source code:
How each works is technology specific, but internally these base images make use of the Docker ONBUILD instruction that specifies commands that are run when these images are used as a base.
For example the following simple Docker file is all that is needed to build a rails application container from the local source code.
FROM rails:onbuild
When working with docker the points 1) and 2) made me struggle a lot. I found out that docker doesn't has the ability to get around these problems natively. My solution is a shell script thats enables you to manage your dockerfiles inside a git repo. You can then build you repo with one command and restart your new containers locally. No need to commit or push. It's also possible to handle multiple dockerfiles in one git repo.
I use this on a daily basis in development and production.
Have a look at this repository https://github.com/Equanox/docker-auto-build