open a file in docker container with vscode
Asked Answered
S

6

14

I need to edit a file in a docker container. as no advanced ide inside the container,I wonder if vscode or some other ide can access into the container and let me edit files as outside the container.

Shakta answered 14/11, 2018 at 3:5 Comment(2)
the only thing i need is to edit, no debug request involved.Shakta
Remember that, when you docker rm the container, any change you make this way is lost; and you need to delete and recreate the container to make a variety of very routine changes (port mappings, environment variables, newer image). It's better to make the change in the image build or push things like config files in using bind mounts (docker run -v option).Alanalana
I
8

With the May, 2nd 2019 announcement of "Remote Development with VS Code", you actually can use The Remote - Containers extension :

https://static.mcmap.net/file/mcmap/ZG-AbGLDKwftZVMwa1MvXn3QXRlAZGyiKmlv/vscode-remote-release/images/remote-containers-readme.gif

The Remote - Containers extension lets you use a Docker container as a full-featured development environment.

Containers make a great development environment because you can:

  • Develop with a consistent and easily reproducible toolchain and on the same operating system you are deploying to.
  • Quickly swap between different, isolated development environments and safely make updates without worrying about impacting your local machine.
  • Make it easy for new team members / contributors to get up and running in a consistent development environment.
Inappreciative answered 2/5, 2019 at 20:55 Comment(0)
F
5

Docker extension for VS Code (ms-azuretools.vscode-docker) allows you to right-click on any running container in the list, then choose 'Attach Visual Studio Code' - and you will be able to open any folder inside Docker container in a new VS Code window. I presume you must have The Remote - Containers extensions installed as well.

Funicular answered 26/5, 2021 at 14:28 Comment(1)
Worked beautifully! Even combines with "VS Code Remote - SSH" to do this on a remote server. This should be the marked answer, simplicity in itself.Dioptometer
G
3

Docker Workspace makes enabled to add folder inside a running docker container.

enter image description here

Goldsmith answered 24/6, 2019 at 16:41 Comment(0)
L
1

You can use the Microsoft Docker Extension in Visual Studio Code (VS Code). Follow these steps:

1. Install Docker Extension:

  • Open VS Code.
  • Go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window or use the shortcut Ctrl + Shift + X.
  • Search for "Docker" in the Extensions view search box.
  • Find the "Docker" extension provided by Microsoft, and click the "Install" button.

2. Use Docker Extension

After the installation is complete, a docker icon will be added in the Activity Bar on the side of the window. Clicking on this icon allows you to view the running containers on your computer. Select your preferred container, and then click on 'Files' to explore all the files inside the container. Now, you can edit each file as needed.

Laicize answered 18/2 at 21:52 Comment(0)
S
0

Try dev container in vscode and it will allow you to connect to the container enter image description here

Sankaran answered 11/6 at 4:55 Comment(0)
I
-2

Start the container by mapping the host path with container path using -v

docker run -v ~/yourlocalpath:/dockerpath

Changes you make on this folder will be reflected inside.

Imhoff answered 6/4, 2019 at 23:55 Comment(1)
It still has to be rebuilt right? Is there an option that as soon as changes are made, the container will reflect it?Was

© 2022 - 2024 — McMap. All rights reserved.