简体   繁体   English

使用 vscode 在 docker 容器中打开一个文件

[英]open a file in docker container with vscode

I need to edit a file in a docker container.我需要在 docker 容器中编辑一个文件。 as no advanced ide inside the container,I wonder if vscode or some other ide can access into the container and let me edit files as outside the container.由于容器内没有高级 ide,我想知道 vscode 或其他一些 ide 是否可以访问容器并让我在容器外编辑文件。

With the May, 2nd 2019 announcement of " Remote Development with VS Code ", you actually can use The Remote - Containers extension :随着 2019 年 5 月 2 日发布的“ 使用 VS 代码进行远程开发”,您实际上可以使用远程 - 容器扩展

https://microsoft.github.io/vscode-remote-release/images/remote-containers-readme.gif

The Remote - Containers extension lets you use a Docker container as a full-featured development environment. Remote - Containers 扩展允许您将 Docker 容器用作功能齐全的开发环境。

Containers make a great development environment because you can:容器可以打造出色的开发环境,因为您可以:

  • Develop with a consistent and easily reproducible toolchain and on the same operating system you are deploying to.使用一致且易于重现的工具链在您要部署到的同一操作系统上进行开发。
  • Quickly swap between different, isolated development environments and safely make updates without worrying about impacting your local machine.在不同的、隔离的开发环境之间快速切换并安全地进行更新,而不必担心影响您的本地机器。
  • Make it easy for new team members / contributors to get up and running in a consistent development environment.让新的团队成员/贡献者可以轻松地在一致的开发环境中启动和运行。

Docker Workspace makes enabled to add folder inside a running docker container. Docker Workspace可以在正在运行的 docker 容器中添加文件夹。

在此处输入图片说明

Docker extension for VS Code (ms-azuretools.vscode-docker) allows you to right-click on any running container in the list, then choose 'Attach Visual Studio Code' - and you will be able to open any folder inside Docker container in a new VS Code window. VS Code 的 Docker 扩展 (ms-azuretools.vscode-docker) 允许您右键单击列表中任何正在运行的容器,然后选择“附加 Visual Studio Code” - 您将能够打开 Docker 容器内的任何文件夹一个新的 VS Code 窗口。 I presume you must have The Remote - Containers extensions installed as well.我想您还必须安装 The Remote - Containers 扩展。

Start the container by mapping the host path with container path using -v通过使用 -v 将主机路径与容器路径映射来启动容器

docker run -v ~/yourlocalpath:/dockerpath docker run -v ~/yourlocalpath:/dockerpath

Changes you make on this folder will be reflected inside.您对此文件夹所做的更改将反映在其中。

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

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