简体   繁体   中英

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.

I want to do this because I want to:

  • run git outside the container
  • be able to run cypress outside the container
  • 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. That is exactly the use case of volumes . I dont know how exactly you start your docker stack or any other info about your setup so that depends. You should try to read and understand how volumes work. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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