64

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.

4
  • 1
    Your local machine is your local development environment, right? So, finally once you're done with development you want to deploy it using containers? Commented Oct 13, 2017 at 9:01
  • 2
    It depends on how much docker your team is going to utilize. One of the selling points of docker is to standardize so that no dev can say "it works on my machine, why doesn't it work on yours?". If a "dev" container is standardized, and everyone uses it, then everyone's libraries and tooling should match.
    – Paul
    Commented Oct 13, 2017 at 9:37
  • 1
    @Shanky i want to develop on my local machine and do the testing on the container as i develop. Lets say i change a file in my project and then run the changes on the container Commented Oct 13, 2017 at 10:16
  • @HopewellMutanda Well, IMO you're looking to have the best of both worlds. The idea for containers is you build what you want and when you're satisfied with it you containerize it. As for a Java application, if you've set the environment carefully inside your container, there is little possibility of the app behaving differently than on your local development setup. Commented Oct 14, 2017 at 18:29

5 Answers 5

23

Updates:


Original post:

There is something that I am not getting when developing an application while using docker containers.

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).

enter image description here

The above image is from [2]

Limitations when setting-up a local dev environment

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.

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.

You can 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 and docker 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 use Dockerfiles. And if your app has different interconnected containers you will have to define all these (networks, links, dependencies) inside a docker-compose.yml file. The repetitive process of building and running will then be your IDE's job...

IDEs & plugins/add-ons

from [1]:

IDE

Docker versions do not provide a native IDE for developing with Docker. The primary interface is the command line API. However, most leading IDEs (NetBeans, Eclipse, IntelliJ, Visual Studio) have some support for Docker through plugins or add-ons.

For example, from [2]:

enter image description here

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:

22
+200

You 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

FROM openjdk:8-jdk-alpine

# ttf-dejavu is required to render GUI under X11: https://github.com/docker-library/openjdk/issues/73
RUN apk --update add --no-cache ttf-dejavu

# install intellij
RUN wget -O /tmp/idea.tar.gz https://download-cf.jetbrains.com/idea/ideaIC-2017.3.4.tar.gz \
    && mkdir -p /usr/share/intellij \
    && tar -xf /tmp/idea.tar.gz --strip-components=1 -C /usr/share/intellij \
    && rm /tmp/idea.tar.gz

docker-compose.yml

version: '3'
services:
  intellij:
    build: .
    environment:
      - DISPLAY=$DISPLAY
    volumes:
      - /tmp/.X11-unix:/tmp/.X11-unix
      - /your/workspace:/tmp/your/workspace
      - idea_cache:/root/.IdeaIC2017.3
      - java_cache:/root/.java
    working_dir: $APP_ROOT
    command: /usr/share/intellij/bin/idea.sh
volumes:
  idea_cache:
  java_cache:
3
  • 7
    Only because you can, it doesn't mean it is a good idea. The entropy introduced by developing inside docker containers largely outweighs its advantages.
    – tiagoboldt
    Commented Feb 19, 2019 at 11:35
  • 1
    @tiagoboldt. Could you please explain what you mean with "entropy introduced by ...". Because I think the solution is good. I guess I am missing something.
    – guettli
    Commented Oct 1, 2020 at 19:42
  • @guettli I am not sure what tiagoboldt meant but my general observation is that it is a very good idea when your host system is linux but when your host system is mac or worse windows you are actually running docker on a linux virtual machine and your X11 sucks. It is passable for somethings but for running gui app containers it is gross.
    – emory
    Commented Oct 2, 2021 at 1:16
2

You need a tooling that implements the Development Containers concept where your local (or optionally cloud based) IDE connects to a Docker container, which provides your development environment. I wrote a blog post about it lately and did a sketch note to explain the concept:

dev-container-concept-drawing

IDEs already implement the concept:

0

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 using maven-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

1
  • 1
    They wanted to avoid having to install libraries on the host, not reuse them in Docker. Commented Dec 15, 2019 at 2:55
0

In fact, it's not necessary to have a local language runtime at all on a host machine

To work like that you need to use a specific CLI tool, like that one or any similar https://github.com/dsboxteam/dsb

It was made specifically to simplify local development in IDE while using Docker containers

Using it when switching to the container, the current working directory and full file paths in subcommand parameters are mapped to the corresponding container's paths (if such a mapping is possible) as well as a current user and permissions from the host machine.

Also, the tool supports the execution of commands in containers via special host scripts which are called identically to the original commands - just under a special prefix.

That allows you to run commands in containers almost as if they were present directly in the host system and provides seamless integration with IDE settings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.