Cannot Attach to Docker Container on VSCode Reload - docker

I am working on a remote server via SSH where docker live.s.
I have created a container with the following code:
docker run -it -d --name <name> -v /data/data:/data python:3.8 /bin/bash
I then attach to the container in VS Code using:
F1 -> "Dev Containers: Attach to Running Container"
I can reload the window fine here. No issues. When I add a folder to the workspace and then reload the window, I am unable to connect to the container anymore. I get an error:
[3888 ms] Start: Run in Host: docker inspect --type container /<name>
[3946 ms] Start: Check Docker is running
[3946 ms] Start: Run in Host: docker version --format {{.Server.APIVersion}}
[4010 ms] Server API version: 1.41
[4054 ms] Command failed: /bin/sh -c cat >'/tmp/devcontainer-config-473d3a31-3938-4870-8f48-d97ddccdab52.json'
[4055 ms] /bin/sh: 1: cannot create /tmp/devcontainer-config-473d3a31-3938-4870-8f48-d97ddccdab52.json: Directory nonexistent
[4055 ms] Exit code 2
Any ideas how to troubleshoot?
I have tried to open permissions to the tmp directory. I have tried to remove workspace folders.
Deleting the imageConfig file allows me to once again open the container in VSCode, but doesn't fix the issue permanently.
C:\Users\name\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\imageConfigs

Related

Directory Nonexistent when Attaching VSCode to running Docker Container

I have a running docker container. I was previously able to connect to this container. During use, I was disconnected. Attempts to reconnect to the docker container (or other variations thereof) are unsuccessful. I've included the logs for this below.
[225 ms] Dev Containers 0.275.1 in VS Code 1.75.0 (e2816fe719a4026ffa1ee0189dc89bdfdbafb164).
[225 ms] Start: Resolving Remote
[227 ms] Setting up container: container_name_redacted
[227 ms] Host: host_redacted
[230 ms] Start: Run: host_redacted /bin/sh
[251 ms] Start: Run in host: id -un
[3684 ms] name_redacted
[3685 ms]
[3685 ms] Start: Run in host: cat /etc/passwd
[3702 ms] Start: Run in host: echo ~
[3719 ms] /home/name_redacted
[3720 ms]
[3721 ms] Start: Run in host: test -x '/home/name_redacted/.vscode-remote-containers/bin/e2816fe719a4026ffa1ee0189dc89bdfdbafb164/node'
[3738 ms]
[3738 ms]
[3739 ms] Start: Run in host: test -f '/home/name_redacted/.vscode-remote-containers/dist/vscode-remote-containers-server-0.275.1.js'
[3756 ms]
[3756 ms]
[3769 ms] userEnvProbe: loginInteractiveShell (default)
[3770 ms] userEnvProbe: not found in cache
[3770 ms] userEnvProbe shell: /bin/bash
[3852 ms] userEnvProbe PATHs:
Probe: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games'
Container: None
[3871 ms] Start: Run in Host: docker inspect --type container /redacted_container_name
[3933 ms] Start: Check Docker is running
[3933 ms] Start: Run in Host: docker version --format {{.Server.APIVersion}}
[3999 ms] Server API version: 1.41
[4047 ms] Command failed: /bin/sh -c cat >'/tmp/devcontainer-config-91de0ba6-e023-476c-b3a0-df813264bd3f.json'
[4047 ms] /bin/sh: 1: cannot create /tmp/devcontainer-config-91de0ba6-e023-476c-b3a0-df813264bd3f.json: Directory nonexistent
[4047 ms] Exit code 2
It looks like it cannot access the /tmp/ directory. I've tried mapping this directory to the container using -v. I've also tried opening up permissions. I've tried creating the container specific to my user. I've tried using privileged parameter. I'm at a loss here.

`$PATH: unknown` error when mounting the current directory in Docker

I want to use Docker to manage multiple Python versions (I recently got a Mac with Apple Silicon and I use old Python environment).
Since I need to read Python scripts on Docker and save the output files (for later use outside the Docker environment), I tried to mount a folder (on my Mac) following this post.
However, it shows this error:
$ docker run --name dpython -it python-docker -v $(pwd):/tmp /bin/bash
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "-v": executable file not found in $PATH: unknown.
ERRO[0000] error waiting for container: context canceled
It works without -v $(pwd):/tmp. I tried to specify different folders such as ~/ and /Users/ but they didn't work.
You must specify the volume before the image name:
$ docker run --name dpython -it -v $(pwd):/tmp python-docker /bin/bash

Docker container after restart:- Failed to connect to bus: No such file or directory

I have created a docker container with the below command.
docker run -it -d --privileged=true Debian-base init
After restart this container when I tried to start any service using systemctl or service or /etc/init.d/ got below error message.
Failed to connect to bus: No such file or directory

Docker-compose - ERROR: no container found after directory change

I use to work on my host on a given directory.
dev_3/
docker-compose-dev.yml
and my docker-compose-dev.yml had a service called 'web' in it, whose container would be called 'web_1', when up'd.
web (service) ---> web_1 (container)
Then I changed my directory path, but keeping the same directory name, 'dev_3'.
When I rebuilt all my images from the same file, docker renamed containers to 'web_2', 'client_2' and so on.
But now If I run this command:
$ docker-compose -f docker-compose-dev.yml exec web python manage.py recreate_db
I get the error:
ERROR: No container found for web_1
which does not exist anymore...so docker is still pointing to a ghost container.
how do i fix this?
I had to use brute force to solve the issue, with this command:
docker container stop $(docker container ls -a -q) && docker system prune -a -f --volumes
And then all started working again, with new built images and fresh containers.

Boot2Docker starting Ubuntu image

I am trying to get the latest Ubuntu image going om my Windows 7/Boot2Docker machine but when i try to start the image i get an error message.
exec: "C:/Program Files (x86)/Git/bin/bash": stat C:/Program Files (x86)/Git/bin/bash: no such file or directory
Full errormessage:
$ docker run -t -i ubuntu /bin/bash
exec: "C:/Program Files (x86)/Git/bin/bash": stat C:/Program Files (x86)/Git/bin/bash: no such file or directory
FATA[0000] Error response from daemon: Cannot start container 100e77a5ac95f8fb8dc55e6382e7a8cd6f946ec807e90d9efdb6fc905a046569: [8] System error: exec: "C:/Program Files (x86)/Git/bin/bash": stat C:/P
rogram Files (x86)/Git/bin/bash: no such file or directory
Any clue on how to work around this? Another image like the default Jenkins one works ok!
The Ubuntu image is pulled correctly
Running Ubuntu image after SSH:
docker#boot2docker:~$ docker run ubuntu
docker#boot2docker:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
It means that somehow your $PATH (within the boot2docker session) includes "C:/Program Files (x86)/Git/bin/" before /bin.
Check the $PATH you have when running docker run --rm -it ubuntu:latest.
The fact that you manage to run the image in a boot2docker ssh session, but docker ps displays nothing seems expected.
Only a docker run --rm -it ubuntu would display a shell.
A simplt docker run would exit the shell immadiatly (non-interactive run), and the container would be in status 'Exited' (see docker ps -a output)
First of all, before you create a container, you have to run "Boot2Docker Start" to start docker virtual machine then start your container inside docker VM. follow up the instructions in this link https://docs.docker.com/installation/windows/
Second, I think that it is preferred to install docker over linux machine not windows, you will get all capabilities of docker.
Best Regards,
Ahmed

Resources