Using an IDE while developing on a docker container

后端 未结 3 2160
野趣味
野趣味 2020-12-07 22:54

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

3条回答
  •  孤街浪徒
    2020-12-07 23:41

    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:
    

提交回复
热议问题