Artur Carvalho
Artur Carvalho

Reputation: 7167

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:

I've tried some configurations mainly related with mounts, but I couldn't make it work.

How would I go about doing this?

Upvotes: 1

Views: 1044

Answers (2)

Mous
Mous

Reputation: 597

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.

Upvotes: 0

Mous
Mous

Reputation: 597

You should try using volumes: https://docs.docker.com/storage/volumes/

Upvotes: 1

Related Questions