[英]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:我想这样做是因为我想:
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.