There is something that I am not getting when developing an application while using docker
containers.
Lets say I am developing a java application and I set up a java container with jdk 8 base image, I still need to install java 8 jdk on my local development machine, since the IDE which I am going to use is going to look for runtime libraries on the local machine not the docker container.
Is this right or am I missing something? Somethings I will be able to do entirely on the docker container like setting up a database but some things I will also have to do on my local development machine and try to match it up with my docker image for example a language runtime like java or python for the sake of using the IDE.
Updates:
Original post:
It's ok, this is not something trivial. Try to see the big picture, it's about creating a Development Pipeline (or CI/CD Pipeline if you like to use the terms Continuous Integration/Continuous Delivery).
The above image is from
[2]
Limitations when setting-up a local dev environment
This is an option that may cause you a problem already mentioned: it may work on your local dev environment and fail elsewhere because you forgot adding a library, a dependency, a minor change that you did without paying attention and keeping in mind to add it to your docker environment.
Better stick to docker while developing
An approach that solves the above problem is to rely on docker[3], in order to set-up the environment you want to use. This means that every time you change something, you will have to
docker build
a new image anddocker run
a new container based on this image. As others have mentioned, to define how your images are going to be built you will have to useDockerfiles
. And if your app has different interconnected containers you will have to define all these (networks, links, dependencies) inside adocker-compose.yml
file. The repetitive process of building and running will then be your IDE's job...IDEs & plugins/add-ons
from
[1]
:For example, from
[2]
:Docker Labs - Developer Tools Tutorials
You can find some guidelines depending on your case (IDE, language...) here:
Shared Volumes | Hot reload | "watching" for file changes
I think this approach matches with your title saying "developing on a docker container" and I mean/understand the case where someone has a running container with a shared volume and whenever a change happens in the code (using the IDE), this affects the container directly. Maybe this will work for a case and have limitations for some other cases. It is up to you to make your assessments and choose your path.
My sources are:
[1]
Docker Reference Architecture: Development Pipeline Best Practices Using Docker EE[2]
Exploring Docker in CI/CD[3]
What is a Container? video from VMware Cloud-NativeYou have the option to run the IDE as a docker container as well, so you don’t need to install anything on your machine.
To do so, you need:
- docker
- X11
- an IDE of your choice.
Take a look at this java project which runs java8 and gradle inside an IntelliJ IDE:
https://github.com/marioluan/java-data-structures
The setup is pretty straightforward:
Dockerfile
docker-compose.yml
I can feel your pain. Developing projects that have multiple library dependencies can make the building process a lot more time consuming, each time a change has been made. This can get frustrating.
Fortunately you can fix this problem by writing your
DockerFile
by usingmaven-docker-plugin
https://github.com/spotify/docker-maven-plugin.This will save use already library dependencies available on your host.
As an example i have a pull request open at an open source repository here: https://github.com/iotaledger/iri/pull/481/files