简体   繁体   English

如何在 docker 容器上运行 VS Code 但共享我的本地文件

[英]How do I run VS Code on a docker container but share my local files

I want to run my code in a local docker container, but I want to change the code files on my operating system and not inside the container.我想在本地 docker 容器中运行我的代码,但我想更改操作系统上的代码文件,而不是容器内的代码文件。

I want to do this because I want to:我想这样做是因为我想:

  • run git outside the container在容器外运行 git
  • be able to run cypress outside the container能够在容器外运行 cypress
  • be able to test my code against different images能够针对不同的图像测试我的代码

I've tried some configurations mainly related with mounts, but I couldn't make it work.我尝试了一些主要与坐骑相关的配置,但我无法使其工作。

How would I go about doing this?我该怎么做呢?

您应该尝试使用卷: https : //docs.docker.com/storage/volumes/

Hey @ArturCarvalho if I understand correctly you just need to be able to modify your code that is running inside a container from VS code on your host.嘿@ArturCarvalho,如果我理解正确,您只需要能够从主机上的 VS 代码修改在容器内运行的代码。 That is exactly the use case of volumes .这正是的使用情况volumes I dont know how exactly you start your docker stack or any other info about your setup so that depends.我不知道你是如何开始你的 docker 堆栈或关于你的设置的任何其他信息,所以这取决于。 You should try to read and understand how volumes work.您应该尝试阅读并理解volumes工作原理。 An example would be:一个例子是:

docker run -d \
  --name test \
  -v /your_path_on_host:/your_path_on_container \
  nginx:latest

This mounts the directory /your_path_on_host inside the container on this path /your_path_on_container and changing anything on your VS code from your HOST on this path should reflect the changes inside the container also on the mounted path./your_path_on_host目录/your_path_on_host挂载到此路径/your_path_on_container上的容器内,并且从该路径上的 HOST 更改 VS 代码上的任何内容应反映容器内的更改也在挂载路径上。

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

相关问题 当连接到 Docker 容器时,如何在 VS Code 中使用本地 git? - How do I use the local git in VS Code, when it is attached to a Docker container? 在 Docker 中,如何从本地目录复制文件,以便我可以将这些文件复制到我的 Docker 容器中? - In Docker, how do I copy files from a local directory so that I can then copy those files into my Docker container? 如何在 Docker 容器中运行 VS Code 的扩展开发主机来测试我的 vscode 扩展? - How can I run VS Code's Extension Development Host in a Docker container to test my vscode extension? 如何将本地文件共享到docker容器中使用docker-compose进行swarm - How to share local files to docker container In swarm with docker-compose 如何在 Docker 容器中运行本地 Python 脚本? - How do I run a local Python script in a Docker container? 如何将本地用户添加到我的 docker 容器? - How do I add the local users to my docker container? 如何配置docker容器在浏览器中运行? - How do I configure my docker container to run in the browser? 如何在我的docker容器中运行pycharm? - How do I run pycharm within my docker container? 如何在我的 docker 容器中运行 Postgres 查询? - How do I run a Postgres query inside my docker container? 泊坞窗。 如何在特定的本地IP上运行我的容器 - Docker. How to run my container on a specific local ip
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM