简体   繁体   English

我的本地Eclipse可以在Docker容器中安装访问库吗?

[英]Can my Local Eclipse Install Access Libraries in Docker Container?

I have a Docker image that I use for Django development, and via some xauthority file mechanics, I use Eclipse from within the container. 我有一个用于Django开发的Docker映像,通过一些xauthority文件机制,我从容器中使用了Eclipse。 For the most part, Eclipse works well, but there are a few nagging issues that seem to be related to the fact it's running inside a container; 在大多数情况下,Eclipse可以很好地运行,但是有一些令人困扰的问题似乎与它在容器中运行有关。 after all, Docker wasn't really developed for this purpose. 毕竟,Docker并不是真正为此目的而开发的。 So, I wonder... 所以,我想知道...

If I run an instance of Eclipse on my local machine, can I configure a given project to access the libraries installed in a running container? 如果我在本地计算机上运行Eclipse的实例,是否可以配置给定的项目以访问安装在运行容器中的库? That is, have it resolve imports, run code using Python 2 or 3/Django 1 or 2 depending on the individual project and the container it's accessing? 也就是说,它是否解析导入,是否使用Python 2或3 / Django 1或2运行代码,具体取决于单个项目及其所访问的容器?

Host Machine: CentOS 7 主机:CentOS 7

Base Image: Ubuntu 16.04 基本映像:Ubuntu 16.04

Added Info: Here is my run command(thought there is some scripting that precedes it for the xauth stuff), which shows how I mount my volumes to a given Docker environment: 添加的信息:这是我的运行命令(在xauth之前有一些脚本),显示了如何将卷安装到给定的Docker环境:

docker run -h django-env \
-d -p 8000:8000 \
-w=/home/$USER \
--user $USER \
-v $XAUTH:$XAUTH -v $XSOCK:$XSOCK \
-v psql_var_lib:/var/lib/postgresql \
-v psql_var_log:/var/log/postgresql \
-v psql_var_etc:/etc/postgresql \
--mount type=bind,source=$LOCAL_REPO/django-env-opt,target=/opt \
--mount type=bind,source=$LOCAL_REPO/django-env-home,target=/home/$USER \
-e XAUTHORITY=$XAUTH -e DISPLAY \
--entrypoint "" hildy:django_python1 bash -c "sudo /etc/init.d/postgresql 
start && /opt/eclipse/eclipse/eclipse"

I use Eclipse from within the container. 我从容器中使用Eclipse。

You don't need to. 不用了 The purpose of the container is to provide you with a compilation environment. 容器的目的是为您提供一个编译环境。 As long as you can share files between the container and host, all code editing can happen from your local eclipse. 只要您可以在容器和主机之间共享文件,所有代码编辑都可以在本地Eclipse中进行。

So the question is how do you share files? 所以问题是如何共享文件? Via volumes. 通过卷。 The simplest way is to say docker run -v <hostdir>:<containerdir> . 最简单的方法是说docker run -v <hostdir>:<containerdir>

Ref: https://docs.docker.com/storage/volumes/ 参考: https : //docs.docker.com/storage/volumes/

First, I'd like to thank @Timir for leading me to the correct answer and helping me realize that I do not need to run Eclipse from within the container. 首先,我要感谢@Timir引导我给出正确的答案,并帮助我意识到我不需要从容器内运行Eclipse。 Trying to do so was just a fundamental misunderstanding about what Docker is for, as this issue came about soon after beginning to learn Docker in the first place. 这样做仅仅是对Docker的根本误解,因为这个问题是在开始学习Docker之后不久就出现的。 You can call me a noob, it's fine, you're not wrong..but on to the resolution. 你可以叫我一个菜鸟,没关系,你没看错..但是关于分辨率。

In my case, what I did was create a volume with docker volume create <volume name I chose> and mounted the volume to the container's /usr/ directory in the run command like so: -v <volume name I chose>:/usr . 就我而言,我要做的是使用docker volume create <volume name I chose>创建一个卷,然后在运行命令中将卷安装到容器的/ usr /目录,如下所示: -v <volume name I chose>:/usr

Next, in Eclipse I navigated to window > preferences > pydev> interpreters > python interpreter > new. 接下来,在Eclipse中,我导航至窗口>首选项> pydev>解释器> python解释器>新建。 Then, I just went to the directory on my host machine where docker volumes live - on my CentOS 7 host, that is /var/lib/docker/volumes/<volume name I chose>/_data/bin/python3.5 -chose that location and gave it a name. 然后,我刚进入Docker卷所在的主机上的目录-在我的CentOS 7主机上,即/var/lib/docker/volumes/<volume name I chose>/_data/bin/python3.5 -chose该位置并为其命名。 Then when I created a given PyDev project, I just chose the interpreter I created and I was in business. 然后,当我创建一个给定的PyDev项目时,我只是选择了我创建的译员并且从事商业活动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM