简体   繁体   English

设置 docker 容器,以便我可以访问 ubuntu 服务器上的 python 包

[英]Setting up docker container so that I can access python packages on ubuntu server

I'm new to using Docker, so I'm either looking for direct help or a link to a relevant guide.我是使用 Docker 的新手,所以我正在寻找直接帮助或相关指南的链接。 I need to train some deep learning models on my school's linux server, but I can't manually install pytorch and other python packages since I don't have root access (sudo).我需要在我学校的 linux 服务器上训练一些深度学习模型,但是我无法手动安装 pytorch 和其他 python 包,因为我没有 root 访问权限(sudo)。 Another student said that he uses docker and has everything ready to go in his container.另一个学生说他使用 docker 并且在他的容器中准备好了一切。

I'm wondering how to wrap up my code and relevant packages into a container that I can push to the linux server and then run.我想知道如何将我的代码和相关包打包到一个容器中,我可以将其推送到 linux 服务器然后运行。

To address your specific problem the easiest way I found to get code into a container is to use git.为了解决您的特定问题,我发现将代码放入容器的最简单方法是使用 git。

  1. start the container in interactive mode or ssh to it if it's attached to a network.如果容器连接到网络,则以交互模式启动容器或通过 ssh 启动容器。

  2. git clone <your awesome deep learning code> . git clone <your awesome deep learning code> In your git repo have a requirements.txt file.在你的 git repo 中有一个requirements.txt文件。 Change directories into your local clone of your repo and run pip install -r requirements.txt将目录更改为存储库的本地克隆并运行pip install -r requirements.txt

  3. Run whatever script you need to run your code.运行运行代码所需的任何脚本。 Note you can easily put your pip install command in one of your run scripts.请注意,您可以轻松地将pip install命令放在您的运行脚本之一中。

It's important to remember that docker containers are stateless/ephemeral.重要的是要记住 docker 容器是无状态/短暂的。 You should not expect the container nor its contents to exist in some durable fashion.您不应该期望容器及其内容以某种持久的方式存在。 This specific issue is addressed by mapping a directory on the host system to a directory in the container.此特定问题已通过将主机系统上的目录映射到容器中的目录来解决。

Side note: I first recommend starting with the docker tutorial .旁注:我首先建议从docker 教程开始 You can easily skip over the installation parts if you are working on system that already has docker installed and where you have permissions to build, start, and stop containers.如果您在已经安装了 docker 并且您有权构建、启动和停止容器的系统上工作,则可以轻松跳过安装部分。

I don't have root access (sudo).我没有 root 访问权限(sudo)。 Another student said that he uses docker另一个同学说他用docker

I would like to point out that docker requires sudo permissions.我想指出docker需要sudo权限。

Instead I think you should look at using something like Google Colab or JupyterLab.相反,我认为您应该考虑使用Google Colab或 JupyterLab 之类的东西。 This gives you the added benefit of code that is backed-up on a remote server这为您提供了在远程服务器上备份的代码的额外好处

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

相关问题 我可以在一个 Docker 容器中安装 Ubuntu、Python 和 Redis 吗? - Can I install Ubuntu, Python and Redis in one Docker container? 无法在带有 Ubuntu 的 docker 容器内安装 pip 包 - Can't install pip packages inside a docker container with Ubuntu 如何使用Python访问Docker容器中的ScyllaDB? - How can I access ScyllaDB in Docker container using Python? 我可以在macOS上为可用于ubuntu docker镜像的python包创建轮子吗? - Can I create wheels for python packages on macOS usable for a ubuntu docker image? 如何挂载 docker 容器以便我可以运行存储在容器内部的 python 脚本 - How to mount a docker container so that I can run python scripts, which are stored in the inside of the container 如何从 ZC5FD214CDD0D2B3B4272E 中的 python 容器脚本连接到 Ubuntu 上的本地 SQL 服务器 - How do I connect to the local SQL server on Ubuntu from a python script in Docker container Docker 容器中缺少 python 包 - Missing python packages in Docker container 如何以与 docker-compose 相同的方式在远程服务器上运行 Docker 容器? - How can I run a Docker container on a remote server in the same manner as docker-compose up? 如何将软件或其他软件包添加到docker容器中? - How can I add software or other packages to a docker container? 无法使用 Dockerfile 连接到 docker 容器(python 服务器) - Can not connect to docker container(python server) with Dockerfile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM