VSCode how to open a local folder within a local docker container.....without devcontainers.json? - docker

I want start a docker container that I have created, and then mount a local folder to it in a way that doesn't make use of a devcontainers.json file. This is because I would like to test the same local repo out with multiple docker containers and editing the devcontainers.json file is a pain because I have to edit every time I want to change the docker image - where really I just want to do something like:
Dev Containers: Open Local Folder in Container
Choose Local Folder
Choose a docker container that is already running
The problem is that in step 3 I only see options to choose from pre-made base images i.e. Ubuntu 22.04. I can't see anywhere in the list any of my docker containers that I am running. Have I missed any functionality? Does what I'm asking exist......or must I use a devcontainers.json file?

If I correctly understood your issue:
Once you install Microsoft's Docker extension from the VS Code extensions' tab (ctrl + shift + x), you'll be able to do that.
This extensions have a "CONTAINERS" tab, where you can open another VSCode window inside a selected container's directory or attach a terminal to the container and manage the system.
Just right-click on the desired container and you'll see the options.

Related

VSCode Docker container not connecting files

I'm using a container for Tensorflow-GPU environment to avoid the hassle of setting one manually and I was following this guide: https://code.visualstudio.com/docs/remote/containers
I've set up the container and installed the necessary extensions and then I try to run "Open Folder in a Container" command. It works fine but none of my files get linked to the new working area inside the docker.
I felt like it was saying that I should get access to all you existing files and folders for the project inside a container.
Is this not how this works? What are the normal way of linking project from the host system onto the docker?
EDIT: This is what I get when I open my container with none of my files present

Is it possible to mount docker container on VS code?

I saw it but I can't remember where I saw it.
It looked like seeing inside Linux, mounting the docker container on VS Code on Mac OS.
Is it possible to mount the docker container on VS code?
By "mount", I presume you're talking about opening VSCode inside the container instead of Docker volumes and bind mounts. You can install the Remote Containers extension to do this.
Also see the docs mentioned by #AttilaViniczai for how to create development containers/dev contianers for VSCode: https://code.visualstudio.com/docs/remote/create-dev-container
Install the VSCode extension
Select the Remote Explorer tab on the left side of VSCode and make sure you have Containers selected from the drop down menu.
Double click the container you want to work on and/or right click and select Attach to Container. This will attach VSCode to that Docker container and install its required tools inside automatically.
For more information about this, you can see the VSCode documentation here and a tutorial here.

"Building Image" task hangs in VS Code Dev Container when using a large directory

I'm using Visual Studio Code on a Windows machine. I'm trying to setup a Python Dev Container using a directory that contains a large set of CSV files (about 200GB). When I click to launch the remote container in Visual Studio the application hangs saying (Starting Dev Container (show log): Building image.
I've been looking through the docs and having read the Advanced Container Configuation I've tried modifying the devcontainer.json file by adding workspaceMount and workspaceFolder entries:
"workspaceMount" : "source=//c/path/to/folder,target=/workspace,type=bind,consistency=delegated"
"workspaceFolder" : "/workspace"
But to no avail. Is there a solution to launching Dev Containers on Windows using folders which contain large files?
I had a slightly different problem, but the solution might help you or someone else. I was trying to run docker-compose inside a docker-in-docker image (provided by vscode). In my case, my container was able to start, but nothing inside the container was able to run.
To solve my issue, I updated vscode and and now there is a new option Remote-Containers: Clone Repository in Container Volume.... If your code is a git repo, you can do this:
Step #1:
Step #2:
Step #3 and onwards:
Follow the given steps provided by vscode and you should have your repository in the container as a volume. It reduced my building times from about 30mins to 3mins (within the running container) because I brought stuff into the container after it was up and running.
Assuming the 200GB is ignored by your .gitignore, what you could try to do is once the container has started, you can copy the 200GB worth of excel files into the container. I thought this would help because I did a similar thing by bringing in all my node_modules after running the container.

How to view docker logs from vscode remote container?

I'm currently using vscode's remote containers extension with a .devcontainer.json file that points to my docker-compose.yml file.
Everything works fine and my docker-compose start command gets run (which launches a web server), but I haven't found a way to quickly see the logs from the web server. Has anyone found a way to view the docker log output automatically once vscode connects to the remote container?
I know as an alternative I could remove my container's start command and, after vscode connects, manually open a terminal and start the web server, but I'm hoping there's an easier way.
Thanks in advance!
I'm not using remote containers, just local once, so not sure if this applies but for locally running containers, you can go to the "Docker" tab (you need to install the official Microsoft Docker VS Code Plugin) where you can see your running containers. Just right-click on the container you want to see the logs for and select "View Logs":
You'll see a new "Task" appear in the Terminal pane that will show all your docker logs:
This question is really old and I'm not sure it this option was available at this time but just open the Command Palette (F1) and select/find "Remote-Containers: Show Log".
You see now the log of your container in the terminal.
You can open the command palette and search for: Remote Explorer: Focus on containers view. You should see a sidebar of containers, if you right click your container you can view logs.
I use VS Code's builtin terminal to see the live logs of the docker container that is connected with VS Code.
When VS Code is connected to the docker container, you can open the builtin terminal using the View > Terminal menu option. You should see an existing terminal labeled Dev Containers.
Maybe this is too late? But for others, this is how I do it.
First, instead of logging stuff to the stdout, I redirect all of the outputs into one single file and then using the tail command to steam the output to the terminal instead.
For example, I am going Go here:
logFile, err := os.OpenFile(logFileName, os.O_WRONLY|os.O_CREATE, 0755)
if err != nil {
log.Fatal("Fail to open the log file")
}
logrus.SetOutput(logFile)
Once that's done, I open up my terminal and run my the following command:
$ tail -f {logFileName}
That's one way to do it I guess, but I sure hope VSCode can come up with a better solution.
In the Remote Explorer tab you can see all your docker containers. Under "Dev Containers" is the container for the service specified in devcontainer.json; the rest are in "Other Containers." Simply right click on the container you're interested in and click "Show Container Log." You'll see the full output of the command for that service, just like in an interactive terminal - not a docker build log!
Note I am using a local development container and did not test with remote containers but I'm guessing it's the same.

Docker won't change VHD location

So I am running on win10 with Hyper-V.
Docker is currently using a harddrive instance thats stored on my C drive (which is an ssd with very little space) I want it on my sshd which is my D drive.
The following is what I tried and has failed, because it looks like Docker just jumps back to its default every time.
change is using the docker interface in the advance section (to a copy of the vhdx file in the d drive)
changing it manually in the hyperv manager by having it migrate the harddrive to a new location
As well as other variations where I restart my computer after doing these.
Use docker > settings > advanced > change vhd location. Notice, you should select an empty directory instead of copy the VHD file by yourself.
Stop / Shutdown Docker
Copy/Move the existing .vhdx from
C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\MobyLinuxVM.vhdx
to
D:\MobyLinuxVM.vhdx (your preferred ssd location)
Edit the Docker settings.json file (%APPDATA%\Docker\settings.json) and configure
"MobyVhdPathOverride": "D:\MobyLinuxVM.vhdx"
Now start the Docker again - the changes should be in place.
When I was having similar problems in that simply changing the Disk image location path would not stick upon a docker restart; this process worked for me:
Create the destination folder, make sure its empty (so no copies of MobyLinuxVM.vhdx)
In Docker>Reset>Restore to factory defaults... restore your docker to factory defaults
In Docker>Settings>Shared Drives give the drive( in your case, D) shared access to docker. Hit apply.
In Docker>Settings>Advanced browse under Disk image location to your destination folder. Hit Apply.
ref: https://github.com/docker/for-win/issues/2063
This is DockerDesktop verison 4.7.1.
Click on the docker icon on the taskbar and go to settings or right click the docker icon on the taskbar and select settings. The window below will popup.
Navigate to the Resources on the left pane and scroll down (if Disk Image Location is not in view). Click on Browse and select an empty folder of your choice. Click on Apply and Restart and Docker Desktop will move the .vhdx from C:\Users\Public\Documents\Hyper-V\Virtual hard disks to your select folder.
If Docker Desktop encounters an error, close Docker Desktop and navigate to C:\Users\<User>\AppData\Roaming\Docker\settings.json and edit the "dataFolder": "D:\\Hyper-V\\Virtual hard disks\\DockerDesktop", to your destination folder. Restart Docker Desktop.

Resources