0

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?

Artur Carvalho
  • 6,901
  • 10
  • 76
  • 105

2 Answers2

1

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

J-Mous
  • 557
  • 3
  • 7
0

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.

J-Mous
  • 557
  • 3
  • 7
  • I can't call it like that, that is called by the vscode-remote plugin. I think I'm close: https://code.visualstudio.com/docs/remote/containers-advanced#_adding-another-local-file-mount. But I get a bunch of errors when I try the mount. That's why I'd like to see a working one. But the error is not informative to me: Command failed: docker run -a STDOUT -a STDERR --mount type=bind,source=c:\Users\ac\Documents\GitHub\a\testproj,target=/workspaces/testproj,consistency=cached --mount source=C:\Users\ac,target=~/,type=bind,consistency=cached -l vsch.quality=stable -l vsch.remote. ... – Artur Carvalho Nov 17 '20 at 09:36