I'm using a multi-container VS Code dev environment exactly as recommended in the docs. My different service environments successfully run using the Dev Containers: Open Folder in Container... as suggested.
Inside the VS Code terminal (in the Docker service container), after every command (e.g. ls) the terminal loads for 5-10 seconds and says Refresh index: 100% (805/805), done which appears to be git refreshing the index. This makes the terminal unusable - how can I stop this?
I think this is happening because the .git folder is part of the workspace volume and is thus copied from my host OS of Windows 11 to my container OS - Linux (Debian 11). But this is what the docs suggest and I need the .git folder to use git inside the repo.
Related
I'm exploring remote container development in VS Code and GitHub Codespaces.
For context, I'm working in Windows 11 on performant Dell XPS 9310 i7 / 32 GB RAM machine.
When I open my Codespace / Dev Container in GitHub Codespaces via the browser, or in VS Code via the > Codespaces: Open in VS Code command, there are no performance issues.
Because I want to know whether development offline is feasible, I am testing having cloned my repo on my local machine, and having opened the repository folder in VS Code locally. This causes a local Docker container to be started in Docker Desktop running on WSL 2. (As expected, Git commands need to be managed outside of VS Code as expected due to permissions, but otherwise looks OK).
A performance issue is apparent when interacting with the terminal (bash or zsh). A terminal prompt takes literal minutes to appear, and to return after every command. I am often stuck waiting for a prompt as shown below after running simple commands requiring few resources.
What is the cause of the poor performance here?
I'm using WSL 2 for Windows, and I'm currently working on a ddev repo where I am creating a development environment using ddev and VSCode. On initiation of the ddev environment, I am starting up all my containers. With my custom "ddev code" command, I am attaching VSCode to the web container via the hex representation of the web container using
'code --folder-uri="vscode-remote://attached-container+646465762d646465762d7673636f64652d646576636f6e7461696e65722d64727570616c392d74656d706c6174652d776562%/var/www/html"'
Now, I would like to automatically enable a bunch of extensions and settings. Currently, I am using workspace settings in my projects folder structure in the form of .vscode/settings.json and extension settings in the form of .vscode/extensions.json. But this is just a workaround, since VSCode will use these settings as "workspace settings" and not "devcontainer settings". I would like to define the settings and install the extensions directly on my attached VSCode container rather than in my workspace settings, since I can only use "recommendations" in the extensions.json, because it is seen as a workspace.
I know I can set the settings and extensions under "AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\imageConfigs" or "nameConfigs" but I would like to have them in Ubuntu or rather in my project's folder directory. I also know that there is the devcontainer.json for standalone VSCode Containers where you can set the Docker files and settings/extensions, but how can I use such a file for my attached container?
Another way would be to install the extensions via command after attaching VSCode using
code --install-extension <extension-id>
But this will only install them locally. And executing this command in the web Container via ssh will throw an error.
Maybe someone knows a solution? If further information is needed I can of course provide it :)
Here is the repository I am working on:
https://github.com/webksde/ddev-vscode-devcontainer-drupal9-template
EDIT: Maybe this issue from our repo can also give more insight:
https://github.com/webksde/ddev-vscode-devcontainer-drupal9-template/issues/28
I have an application consisting of a Flask web application and a RQ worker application. Both live in separate containers but use the same image. I would like to use Visual Studio Code's Remote Extension to run the containers and debug inside them. This all works well for either container using devcontainer.json and the automatically generated .devcontainer/docker-compose.yml which overwrite mine partially.
This Article explains that connecting to multiple containers is possible using multiple windows. They assume the two containers to have different source, stored in different folders which can be used to store separate devcontainer.json files.
I don't understand though how to configure the startup. When starting any of the two containers I would need the other one to start as well. That's easily achieved using the original docker-compose.yml. I could then manually run and debug the application in the started devcontainer.
Yet how would I connect to the other, then also running container and run and debug there?
First, install the Docker extension.
In VS Code, you can right-click on the docker-compose.yaml File and click on compose up to start all the containers.
You debug your script in exactly one terminal shell. This is the reason why you have just one VS Code window per container.
However, you can attach VS Code afterwards to as many already started containers as you like (e.g. after docker compose up) by right-click on the container and click on Attach Visual Studio code in the Docker tab.
I am currently working with a remote docker container which is running locally on my computer, mainly Python.
I have several extensions listed on devcontainer.json so when the docker is build it install these package.
I am tryin to avoid reinstalling some of these extensions every time I rebuild or reopen the project.
Specially with Pylance and Python which require to reload the project within VScode.
Any suggestions?
Yo, put a volume over /root/.vscode-server or symlink the whole vscode server folder to a.tmp folder within the project, and then also put that folder into a persistant docker folume :)
# entrypoint.sh
echo "[Operation] Symlink vscode-server (for developers that use it)"
mkdir -p /app/.tmp/.vscode-server \
&& ln -s /app/.tmp/.vscode-server /root/.vscode-server
There is a detailed description on the official vscode docs:
[https://code.visualstudio.com/remote/advancedcontainers/avoid-extension-reinstalls][1]
This creates a docker volume on the host. The extensions will need to be installed inside the container only once because the files will be persisted on the host volume hence survive any container rebuilds.
I'm using a remote machine, and want to run a docker inside that machine (local->remote->docker) and wish to use the Remote development in Containers tools of vs code
Unfortunatlly, I do not see any of the actions after installing the extension.
My view (ctrl+shift+p -> type remote-containers)
While the tutorial has actions I don't even see:
You need to make sure you are not connected to your remote host via Remote-SSH in VSCode. If you are, you will not see "Open Folder in Container..." or the other options.
Try opening up VSCode without connecting using Remote-SSH. You will find that the option is now present.
To set up a remote Docker host, you first need to be able to access your remote host using key based authentication as describe here
You then set
"docker.host":"ssh://your-remote-user#your-remote-machine-fqdn-or-ip-here"
in setting.json.
Once that is setup, you can only attach to running containers. Test this out before proceeding:
Start a container on the remote host
Hit F1 in your vscode and then select "Attach to Running Container..."
You should see the container you started and you should be able to attach to this
Once you are past this point, you will need to create your devcontainer.json file as per the documentation
Make sure you have installed Remote Container extension.
and ssh as mentioned on the comment above.
Once installed, click on Docker icon, under containers, right click on the container you need to work with vcode and select attach vscode.
I had this issue when I opened vscode for the first time in a year after only needing to install it for some random project that wanted me to use "dev containers" for, I don't remember what.
But I don't care about dev containers anymore and I don't remember that project, however, vscode was functionally unusable because it opened in that old project directory and was trying to do... something with containers. I don't know, I don't care, I just wanted to open another folder so a junior programmer could use an IDE on my machine they're familiar with instead of emacs/vim/whatever.
The solution for me was to use the "extensions" tab CTRL+SHIFT+X, disable the "Dev Containers" extension, then use "File -> Open Recent Folder" to select some other directory. This gets around the "can't open in container" bug. If you don't have a history of other opened directories, I think you need to completely reinstall Vscode or something.