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.
With the May, 2nd 2019 announcement of "Remote Development with VS Code", you actually can use The Remote - Containers extension :
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.
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.
Docker Workspace makes enabled to add folder inside a running docker container.
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.
Try dev container in vscode and it will allow you to connect to the container enter image description here
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.
© 2022 - 2024 — McMap. All rights reserved.
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