在 docker 容器上开发时使用 IDE [英] Using an IDE while developing on a docker container

查看:25
本文介绍了在 docker 容器上开发时使用 IDE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 docker 容器开发应用程序时,我没有得到一些东西.

假设我正在开发一个 java 应用程序并且我设置了一个带有 jdk 8 基本映像的 java 容器,我仍然需要在我的本地开发机器上安装 java 8 jdk,因为我将要使用的 IDE 将在本地机器上寻找运行时库,而不是 docker 容器.

这是正确的还是我遗漏了什么?有些事情我可以完全在 docker 容器上做,比如设置数据库,但有些事情我也必须在本地开发机器上做,并尝试将它与我的 docker 镜像匹配,例如像 java 或 python 这样的语言运行时为了使用IDE.

解决方案

更新:

  • 2018/04/17:

    上图来自[2]

    设置本地开发环境时的限制

    <块引用>

    假设我正在开发一个 java 应用程序并且我设置了一个带有 jdk 8 基本映像的 java 容器,我仍然需要在我的本地开发机器上安装 java 8 jdk,因为我要使用的 IDE将在本地机器上寻找运行时库,而不是 docker 容器.

    这是一个可能会导致您已经提到的问题的选项:它可能会在您的本地开发环境中运行并在其他地方失败,因为您忘记添加库,依赖项,您在没有注意和记住的情况下所做的微小更改将其添加到您的 docker 环境中.

    你可以一边开发一边坚持使用docker

    解决上述问题的一种方法是依赖docker[3],以便设置您要使用的环境.这意味着每次更改某些内容时,您都必须docker build 一个新镜像,然后 docker run 一个基于此镜像的新容器.正如其他人提到的,要定义您的图像将如何构建,您必须使用 Dockerfiles.如果您的应用程序具有不同的互连容器,则必须在 docker-compose.yml 文件中定义所有这些(网络、链接、依赖项).构建和运行的重复过程将成为您的 IDE 的工作......

    IDE 和插件/附加组件

    来自[1]:

    <块引用>

    集成开发环境

    Docker 版本不提供用于使用 Docker 进行开发的本机 IDE.主要接口是命令行 API.但是,大多数领先的 IDE(NetBeans、Eclipse、IntelliJ、Visual Studio)都通过插件或附加组件支持 Docker.

    例如,来自[2]:

    Docker 实验室 - 开发者工具教程

    根据您的情况(IDE、语言...),您可以在此处找到一些指南:

    共享卷 |热重载 |看着"用于文件更改

    我认为这种方法与您的标题相匹配,即在 docker 容器上开发",我的意思是/理解某人拥有一个共享卷的正在运行的容器以及每当发生更改时的情况代码(使用 IDE),这会直接影响容器.也许这适用于一个案例,但对其他一些案例有限制.您可以进行评估并选择自己的道路.

    我的来源是:

    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:

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

    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]:

    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:

    这篇关于在 docker 容器上开发时使用 IDE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆