How can I develop in docker container with intellij? How can I develop in docker container with intellij? docker docker

How can I develop in docker container with intellij?


So you just want to work within a container just as you would within a full-blown VM, right? Then you should just run a container, attach a display (to run IDEA) and start configuring your development environment. For the display part I'd test some answers given in Can you run GUI apps in a docker container?. There are some very cool answers in this topic showing various approaches to running GUI apps within a container.


Please look at this example for Intellij IDEA CI and JDK8 based on Alpine Linux (taken here https://raw.githubusercontent.com/shaharv/docker/master/alpine/dev/Dockerfile)

# Alpine 3.8 C++/Java Developer Image## For IntelliJ and GUI (X11), run the image with:# $ XSOCK=/tmp/.X11-unix && sudo docker run -i -v $XSOCK:$XSOCK -e DISPLAY -u developer -t [image-name]## Then run IntelliJ with:# /idea-IC-191.6707.61/bin/idea.shFROM alpine:3.8ENV LANG C.UTF-8RUN set -ex && \    apk add --no-cache --update \    # basic packages        bash bash-completion coreutils file grep openssl openssh nano sudo tar xz \    # debug tools        gdb musl-dbg strace \    # docs and man        bash-doc man man-pages less less-doc \    # GUI fonts        font-noto \    # user utils        shadowRUN set -ex && \    apk add --no-cache --update \    # C++ build tools        cmake g++ git linux-headers libpthread-stubs makeRUN set -ex && \    apk add --no-cache --update \    # Java tools        gradle openjdk8 openjdk8-dbg# Install IntelliJ CommunityRUN set -ex && \    wget https://download-cf.jetbrains.com/idea/ideaIC-2019.1.1-no-jbr.tar.gz && \    tar -xf ideaIC-2019.1.1-no-jbr.tar.gz && \    rm ideaIC-2019.1.1-no-jbr.tar.gz# Create a new user with no passwordENV USERNAME developerRUN set -ex && \    useradd --create-home --key MAIL_DIR=/dev/null --shell /bin/bash $USERNAME && \    passwd -d $USERNAME# Set additional environment variablesENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdkENV JDK_HOME  /usr/lib/jvm/java-1.8-openjdkENV JAVA_EXE  /usr/lib/jvm/java-1.8-openjdk/bin/java


Shouldn't the approach be rather:Have local repository and local IDE. In the repository have docker file and eventually docker-compose.yml, which spins up environment required to run project.Mount your local drive with sources into docker (volumes), so changes done in your local folder are reflected in docker, similar in other direction.