Failed to bind ssh port for container #1

Open
opened 2024-12-04 23:22:04 +00:00 by ridhwaans · 12 comments
ridhwaans commented 2024-12-04 23:22:04 +00:00 (Migrated from github.com)

Env: Ubuntu 24.04.1 LTS
On the latest master

web .env

VITE_VERSION=0.1.0

# where the api is hosted. this is usually left empty because the same server serves the web and the api
VITE_API_URL=http://localhost:8080

# the host name of where tesseract is deployed
VITE_HOST_NAME=localhost

config.json

{
  "port": 8080,
  "databasePath": "./data.sqlite",
  "hostName": "localhost",
  "debug": true
}

template name: dec-4-image
base: fedora 40 + openssh server + docker
build arguments:
user=test
password=test

new workspace name: dec-4-workspace
image: dec-4-image
docker runtime: nvidia (also selected runc; same effect)
image

go log

DOCKER LOG:  {"stream":" ---\u003e 69642b1418c9\n"}
DOCKER LOG:  {"stream":"Step 5/5 : CMD [\"/usr/sbin/sshd\", \"-D\"]"}
DOCKER LOG:  {"stream":"\n"}
DOCKER LOG:  {"stream":" ---\u003e Running in a4b193fbb783\n"}
DOCKER LOG:  {"stream":" ---\u003e 2c8a100adeed\n"}
DOCKER LOG:  {"aux":{"ID":"sha256:2c8a100adeed91e926fe84d83a9bd932b3ce0a5ee2f9aa95a310d130b0d9b200"}}
DOCKER LOG:  {"stream":"Successfully built 2c8a100adeed\n"}
DOCKER LOG:  {"stream":"Successfully tagged dec-4-image:latest\n"}
[bun]  15:03:34.750   INSERT                1.513ms  INSERT INTO "template_images" AS "template_images" ("template_id", "image_tag", "image_id") VALUES ('019393e4-24ef-7b66-abf9-7f97f13d9a00', 'dec-4-image', 'sha256:2c8a100adeed91e926fe84d83a9bd932b3ce0a5ee2f9aa95a310d130b0d9b200') ON CONFLICT DO UPDATE SET image_id = EXCLUDED.image_id
[bun]  15:03:34.763   COMMIT               11.964ms  COMMIT
[bun]  15:03:59.434   SELECT                  436µs  SELECT "template"."id", "template"."name", "template"."description", "template"."created_on", "template"."last_modified_on", "template"."is_built" FROM "templates" AS "template"
[bun]  15:04:00.226   SELECT                  399µs  SELECT "workspace"."id", "workspace"."name", "workspace"."container_id", "workspace"."image_tag", "workspace"."created_at", "workspace"."runtime" FROM "workspaces" AS "workspace"
[bun]  15:04:00.227   SELECT                  183µs  SELECT "template_images"."template_id", "template_images"."image_tag", "template_images"."image_id" FROM "template_images"
[bun]  15:04:11.187   SELECT                5.684ms  SELECT "workspace"."id", "workspace"."name", "workspace"."container_id", "workspace"."image_tag", "workspace"."created_at", "workspace"."runtime" FROM "workspaces" AS "workspace" WHERE (name = 'dec-4-workspace')           *errors.errorString: sql: no rows in result set 
[bun]  15:04:11.210   BEGIN                    45µs  BEGIN
[bun]  15:04:11.210   SELECT                  147µs  SELECT "template_images"."template_id", "template_images"."image_tag", "template_images"."image_id" FROM "template_images" WHERE (image_id = 'sha256:2c8a100adeed91e926fe84d83a9bd932b3ce0a5ee2f9aa95a310d130b0d9b200')
{"time":"2024-12-04T15:04:12.269589873-08:00","level":"ERROR","prefix":"echo","file":"main.go","line":"101","message":"failed to bind ssh port for container"}
[bun]  15:05:13.819   SELECT                  342µs  SELECT "workspace"."id", "workspace"."name", "workspace"."container_id", "workspace"."image_tag", "workspace"."created_at", "workspace"."runtime" FROM "workspaces" AS "workspace"

{"time":"2024-12-04T15:04:12.269589873-08:00","level":"ERROR","prefix":"echo","file":"main.go","line":"101","message":"failed to bind ssh port for container"}

The toast message gives a workspace create error, but when i check docker desktop the workspace seems to be created

image
image

Env: Ubuntu 24.04.1 LTS On the latest master web .env ```javascript VITE_VERSION=0.1.0 # where the api is hosted. this is usually left empty because the same server serves the web and the api VITE_API_URL=http://localhost:8080 # the host name of where tesseract is deployed VITE_HOST_NAME=localhost ``` config.json ```json { "port": 8080, "databasePath": "./data.sqlite", "hostName": "localhost", "debug": true } ``` template name: dec-4-image base: fedora 40 + openssh server + docker build arguments: user=test password=test new workspace name: dec-4-workspace image: dec-4-image docker runtime: nvidia (also selected runc; same effect) ![image](https://github.com/user-attachments/assets/227810b8-6c8b-43f6-a9f9-5e8b9daaec2e) go log ```javascript DOCKER LOG: {"stream":" ---\u003e 69642b1418c9\n"} DOCKER LOG: {"stream":"Step 5/5 : CMD [\"/usr/sbin/sshd\", \"-D\"]"} DOCKER LOG: {"stream":"\n"} DOCKER LOG: {"stream":" ---\u003e Running in a4b193fbb783\n"} DOCKER LOG: {"stream":" ---\u003e 2c8a100adeed\n"} DOCKER LOG: {"aux":{"ID":"sha256:2c8a100adeed91e926fe84d83a9bd932b3ce0a5ee2f9aa95a310d130b0d9b200"}} DOCKER LOG: {"stream":"Successfully built 2c8a100adeed\n"} DOCKER LOG: {"stream":"Successfully tagged dec-4-image:latest\n"} [bun] 15:03:34.750 INSERT 1.513ms INSERT INTO "template_images" AS "template_images" ("template_id", "image_tag", "image_id") VALUES ('019393e4-24ef-7b66-abf9-7f97f13d9a00', 'dec-4-image', 'sha256:2c8a100adeed91e926fe84d83a9bd932b3ce0a5ee2f9aa95a310d130b0d9b200') ON CONFLICT DO UPDATE SET image_id = EXCLUDED.image_id [bun] 15:03:34.763 COMMIT 11.964ms COMMIT [bun] 15:03:59.434 SELECT 436µs SELECT "template"."id", "template"."name", "template"."description", "template"."created_on", "template"."last_modified_on", "template"."is_built" FROM "templates" AS "template" [bun] 15:04:00.226 SELECT 399µs SELECT "workspace"."id", "workspace"."name", "workspace"."container_id", "workspace"."image_tag", "workspace"."created_at", "workspace"."runtime" FROM "workspaces" AS "workspace" [bun] 15:04:00.227 SELECT 183µs SELECT "template_images"."template_id", "template_images"."image_tag", "template_images"."image_id" FROM "template_images" [bun] 15:04:11.187 SELECT 5.684ms SELECT "workspace"."id", "workspace"."name", "workspace"."container_id", "workspace"."image_tag", "workspace"."created_at", "workspace"."runtime" FROM "workspaces" AS "workspace" WHERE (name = 'dec-4-workspace') *errors.errorString: sql: no rows in result set [bun] 15:04:11.210 BEGIN 45µs BEGIN [bun] 15:04:11.210 SELECT 147µs SELECT "template_images"."template_id", "template_images"."image_tag", "template_images"."image_id" FROM "template_images" WHERE (image_id = 'sha256:2c8a100adeed91e926fe84d83a9bd932b3ce0a5ee2f9aa95a310d130b0d9b200') {"time":"2024-12-04T15:04:12.269589873-08:00","level":"ERROR","prefix":"echo","file":"main.go","line":"101","message":"failed to bind ssh port for container"} [bun] 15:05:13.819 SELECT 342µs SELECT "workspace"."id", "workspace"."name", "workspace"."container_id", "workspace"."image_tag", "workspace"."created_at", "workspace"."runtime" FROM "workspaces" AS "workspace" ``` > {"time":"2024-12-04T15:04:12.269589873-08:00","level":"ERROR","prefix":"echo","file":"main.go","line":"101","message":"failed to bind ssh port for container"} The toast message gives a workspace create error, but when i check docker desktop the workspace seems to be created ![image](https://github.com/user-attachments/assets/090515eb-2957-4b96-a99b-e25fdfc75aff) ![image](https://github.com/user-attachments/assets/f9b98a3f-240b-4da4-bca6-7ab29adcb609)
kennethnym commented 2024-12-05 13:48:44 +00:00 (Migrated from github.com)

i tried to reproduce the issue with your config but can't. somehow port 22 isn't exposed for the workspace on your end. can you run:

docker container ls --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}" -a

and paste the output? mine looks like this:

Screenshot 2024-12-05 at 13 46 29

as you can see port 22 is correctly exposed. also what OS are you running tesseract on?

i tried to reproduce the issue with your config but can't. somehow port 22 isn't exposed for the workspace on your end. can you run: ```shell docker container ls --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}" -a ``` and paste the output? mine looks like this: <img width="820" alt="Screenshot 2024-12-05 at 13 46 29" src="https://github.com/user-attachments/assets/48be8863-582e-4bc9-8a36-d2f4aab06dad"> as you can see port 22 is correctly exposed. also what OS are you running tesseract on?
ridhwaans commented 2024-12-05 17:03:53 +00:00 (Migrated from github.com)

OS is Ubuntu 24.04.1 LTS on WSL2 on Windows11
image

OS is Ubuntu 24.04.1 LTS on WSL2 on Windows11 ![image](https://github.com/user-attachments/assets/2bc44778-c49e-4a16-a14e-a2fe0a1cbe81)
kennethnym commented 2024-12-05 17:12:54 +00:00 (Migrated from github.com)

strange. can you run

docker container inspect -f json dec-4-workspace
strange. can you run ```shell docker container inspect -f json dec-4-workspace ```
ridhwaans commented 2024-12-05 17:19:49 +00:00 (Migrated from github.com)
docker container inspect -f json dec-4-workspace
[{"Id":"857169bc380a8f7f4231261c3e5dd23ed2c9fe193535e0cedc44a3093cc18673","Created":"2024-12-04T23:05:13.141781528Z","Path":"/usr/sbin/sshd","Args":["-D"],"State":{"Status":"exited","Running":false,"Paused":false,"Restarting":false,"OOMKilled":false,"Dead":false,"Pid":0,"ExitCode":255,"Error":"","StartedAt":"2024-12-04T23:05:13.309679559Z","FinishedAt":"2024-12-05T06:50:47.945650245Z"},"Image":"sha256:2c8a100adeed91e926fe84d83a9bd932b3ce0a5ee2f9aa95a310d130b0d9b200","ResolvConfPath":"/var/lib/docker/containers/857169bc380a8f7f4231261c3e5dd23ed2c9fe193535e0cedc44a3093cc18673/resolv.conf","HostnamePath":"/var/lib/docker/containers/857169bc380a8f7f4231261c3e5dd23ed2c9fe193535e0cedc44a3093cc18673/hostname","HostsPath":"/var/lib/docker/containers/857169bc380a8f7f4231261c3e5dd23ed2c9fe193535e0cedc44a3093cc18673/hosts","LogPath":"/var/lib/docker/containers/857169bc380a8f7f4231261c3e5dd23ed2c9fe193535e0cedc44a3093cc18673/857169bc380a8f7f4231261c3e5dd23ed2c9fe193535e0cedc44a3093cc18673-json.log","Name":"/dec-4-workspace","RestartCount":0,"Driver":"overlay2","Platform":"linux","MountLabel":"","ProcessLabel":"","AppArmorProfile":"","ExecIDs":null,"HostConfig":{"Binds":null,"ContainerIDFile":"","LogConfig":{"Type":"json-file","Config":{}},"NetworkMode":"bridge","PortBindings":{"22/tcp":[{"HostIp":"127.0.0.1","HostPort":"0"}]},"RestartPolicy":{"Name":"no","MaximumRetryCount":0},"AutoRemove":false,"VolumeDriver":"","VolumesFrom":null,"ConsoleSize":[0,0],"CapAdd":null,"CapDrop":null,"CgroupnsMode":"host","Dns":[],"DnsOptions":[],"DnsSearch":[],"ExtraHosts":null,"GroupAdd":null,"IpcMode":"private","Cgroup":"","Links":null,"OomScoreAdj":0,"PidMode":"","Privileged":false,"PublishAllPorts":false,"ReadonlyRootfs":false,"SecurityOpt":null,"UTSMode":"","UsernsMode":"","ShmSize":67108864,"Runtime":"nvidia","Isolation":"","CpuShares":0,"Memory":0,"NanoCpus":0,"CgroupParent":"","BlkioWeight":0,"BlkioWeightDevice":null,"BlkioDeviceReadBps":null,"BlkioDeviceWriteBps":null,"BlkioDeviceReadIOps":null,"BlkioDeviceWriteIOps":null,"CpuPeriod":0,"CpuQuota":0,"CpuRealtimePeriod":0,"CpuRealtimeRuntime":0,"CpusetCpus":"","CpusetMems":"","Devices":null,"DeviceCgroupRules":null,"DeviceRequests":null,"MemoryReservation":0,"MemorySwap":0,"MemorySwappiness":null,"OomKillDisable":false,"PidsLimit":null,"Ulimits":null,"CpuCount":0,"CpuPercent":0,"IOMaximumIOps":0,"IOMaximumBandwidth":0,"MaskedPaths":["/proc/asound","/proc/acpi","/proc/kcore","/proc/keys","/proc/latency_stats","/proc/timer_list","/proc/timer_stats","/proc/sched_debug","/proc/scsi","/sys/firmware","/sys/devices/virtual/powercap"],"ReadonlyPaths":["/proc/bus","/proc/fs","/proc/irq","/proc/sys","/proc/sysrq-trigger"]},"GraphDriver":{"Data":{"LowerDir":"/var/lib/docker/overlay2/bb6dd291b9395a2b0f0540e4dc77a912afc8a31272b9ff605be6e270e4b6a014-init/diff:/var/lib/docker/overlay2/ff8d523f8f49fd52a022ab5be108726661afa70f42dc6f4f4732597e176e7788/diff:/var/lib/docker/overlay2/e14d83c248614a9d3184d5b7ce34cde30ef59b95ef4b0f2fd68fafb490c6098f/diff","MergedDir":"/var/lib/docker/overlay2/bb6dd291b9395a2b0f0540e4dc77a912afc8a31272b9ff605be6e270e4b6a014/merged","UpperDir":"/var/lib/docker/overlay2/bb6dd291b9395a2b0f0540e4dc77a912afc8a31272b9ff605be6e270e4b6a014/diff","WorkDir":"/var/lib/docker/overlay2/bb6dd291b9395a2b0f0540e4dc77a912afc8a31272b9ff605be6e270e4b6a014/work"},"Name":"overlay2"},"Mounts":[],"Config":{"Hostname":"857169bc380a","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":{"22/tcp":{}},"Tty":true,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","DISTTAG=f40container","FGC=f40","FBR=f40"],"Cmd":["/usr/sbin/sshd","-D"],"Image":"sha256:2c8a100adeed91e926fe84d83a9bd932b3ce0a5ee2f9aa95a310d130b0d9b200","Volumes":null,"WorkingDir":"/","Entrypoint":null,"OnBuild":null,"Labels":{"desktop.docker.io/wsl-distro":"Ubuntu","maintainer":"Clement Verna \u003ccverna@fedoraproject.org\u003e"}},"NetworkSettings":{"Bridge":"","SandboxID":"","SandboxKey":"","Ports":{},"HairpinMode":false,"LinkLocalIPv6Address":"","LinkLocalIPv6PrefixLen":0,"SecondaryIPAddresses":null,"SecondaryIPv6Addresses":null,"EndpointID":"","Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"IPAddress":"","IPPrefixLen":0,"IPv6Gateway":"","MacAddress":"","Networks":{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"MacAddress":"","DriverOpts":null,"NetworkID":"8082183bef5cc021be311efae25182a3c84ac3eef74892867efdf6535eba564f","EndpointID":"","Gateway":"","IPAddress":"","IPPrefixLen":0,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"DNSNames":null}}}}]
```javascript docker container inspect -f json dec-4-workspace [{"Id":"857169bc380a8f7f4231261c3e5dd23ed2c9fe193535e0cedc44a3093cc18673","Created":"2024-12-04T23:05:13.141781528Z","Path":"/usr/sbin/sshd","Args":["-D"],"State":{"Status":"exited","Running":false,"Paused":false,"Restarting":false,"OOMKilled":false,"Dead":false,"Pid":0,"ExitCode":255,"Error":"","StartedAt":"2024-12-04T23:05:13.309679559Z","FinishedAt":"2024-12-05T06:50:47.945650245Z"},"Image":"sha256:2c8a100adeed91e926fe84d83a9bd932b3ce0a5ee2f9aa95a310d130b0d9b200","ResolvConfPath":"/var/lib/docker/containers/857169bc380a8f7f4231261c3e5dd23ed2c9fe193535e0cedc44a3093cc18673/resolv.conf","HostnamePath":"/var/lib/docker/containers/857169bc380a8f7f4231261c3e5dd23ed2c9fe193535e0cedc44a3093cc18673/hostname","HostsPath":"/var/lib/docker/containers/857169bc380a8f7f4231261c3e5dd23ed2c9fe193535e0cedc44a3093cc18673/hosts","LogPath":"/var/lib/docker/containers/857169bc380a8f7f4231261c3e5dd23ed2c9fe193535e0cedc44a3093cc18673/857169bc380a8f7f4231261c3e5dd23ed2c9fe193535e0cedc44a3093cc18673-json.log","Name":"/dec-4-workspace","RestartCount":0,"Driver":"overlay2","Platform":"linux","MountLabel":"","ProcessLabel":"","AppArmorProfile":"","ExecIDs":null,"HostConfig":{"Binds":null,"ContainerIDFile":"","LogConfig":{"Type":"json-file","Config":{}},"NetworkMode":"bridge","PortBindings":{"22/tcp":[{"HostIp":"127.0.0.1","HostPort":"0"}]},"RestartPolicy":{"Name":"no","MaximumRetryCount":0},"AutoRemove":false,"VolumeDriver":"","VolumesFrom":null,"ConsoleSize":[0,0],"CapAdd":null,"CapDrop":null,"CgroupnsMode":"host","Dns":[],"DnsOptions":[],"DnsSearch":[],"ExtraHosts":null,"GroupAdd":null,"IpcMode":"private","Cgroup":"","Links":null,"OomScoreAdj":0,"PidMode":"","Privileged":false,"PublishAllPorts":false,"ReadonlyRootfs":false,"SecurityOpt":null,"UTSMode":"","UsernsMode":"","ShmSize":67108864,"Runtime":"nvidia","Isolation":"","CpuShares":0,"Memory":0,"NanoCpus":0,"CgroupParent":"","BlkioWeight":0,"BlkioWeightDevice":null,"BlkioDeviceReadBps":null,"BlkioDeviceWriteBps":null,"BlkioDeviceReadIOps":null,"BlkioDeviceWriteIOps":null,"CpuPeriod":0,"CpuQuota":0,"CpuRealtimePeriod":0,"CpuRealtimeRuntime":0,"CpusetCpus":"","CpusetMems":"","Devices":null,"DeviceCgroupRules":null,"DeviceRequests":null,"MemoryReservation":0,"MemorySwap":0,"MemorySwappiness":null,"OomKillDisable":false,"PidsLimit":null,"Ulimits":null,"CpuCount":0,"CpuPercent":0,"IOMaximumIOps":0,"IOMaximumBandwidth":0,"MaskedPaths":["/proc/asound","/proc/acpi","/proc/kcore","/proc/keys","/proc/latency_stats","/proc/timer_list","/proc/timer_stats","/proc/sched_debug","/proc/scsi","/sys/firmware","/sys/devices/virtual/powercap"],"ReadonlyPaths":["/proc/bus","/proc/fs","/proc/irq","/proc/sys","/proc/sysrq-trigger"]},"GraphDriver":{"Data":{"LowerDir":"/var/lib/docker/overlay2/bb6dd291b9395a2b0f0540e4dc77a912afc8a31272b9ff605be6e270e4b6a014-init/diff:/var/lib/docker/overlay2/ff8d523f8f49fd52a022ab5be108726661afa70f42dc6f4f4732597e176e7788/diff:/var/lib/docker/overlay2/e14d83c248614a9d3184d5b7ce34cde30ef59b95ef4b0f2fd68fafb490c6098f/diff","MergedDir":"/var/lib/docker/overlay2/bb6dd291b9395a2b0f0540e4dc77a912afc8a31272b9ff605be6e270e4b6a014/merged","UpperDir":"/var/lib/docker/overlay2/bb6dd291b9395a2b0f0540e4dc77a912afc8a31272b9ff605be6e270e4b6a014/diff","WorkDir":"/var/lib/docker/overlay2/bb6dd291b9395a2b0f0540e4dc77a912afc8a31272b9ff605be6e270e4b6a014/work"},"Name":"overlay2"},"Mounts":[],"Config":{"Hostname":"857169bc380a","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"ExposedPorts":{"22/tcp":{}},"Tty":true,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","DISTTAG=f40container","FGC=f40","FBR=f40"],"Cmd":["/usr/sbin/sshd","-D"],"Image":"sha256:2c8a100adeed91e926fe84d83a9bd932b3ce0a5ee2f9aa95a310d130b0d9b200","Volumes":null,"WorkingDir":"/","Entrypoint":null,"OnBuild":null,"Labels":{"desktop.docker.io/wsl-distro":"Ubuntu","maintainer":"Clement Verna \u003ccverna@fedoraproject.org\u003e"}},"NetworkSettings":{"Bridge":"","SandboxID":"","SandboxKey":"","Ports":{},"HairpinMode":false,"LinkLocalIPv6Address":"","LinkLocalIPv6PrefixLen":0,"SecondaryIPAddresses":null,"SecondaryIPv6Addresses":null,"EndpointID":"","Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"IPAddress":"","IPPrefixLen":0,"IPv6Gateway":"","MacAddress":"","Networks":{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"MacAddress":"","DriverOpts":null,"NetworkID":"8082183bef5cc021be311efae25182a3c84ac3eef74892867efdf6535eba564f","EndpointID":"","Gateway":"","IPAddress":"","IPPrefixLen":0,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"DNSNames":null}}}}] ```
kennethnym commented 2024-12-05 17:27:40 +00:00 (Migrated from github.com)

it says the container is not running:

Screenshot 2024-12-05 at 17 26 23

do you get the same error if you create another workspace? can you try fedora 40 with openssh for the base template?

it says the container is not running: <img width="503" alt="Screenshot 2024-12-05 at 17 26 23" src="https://github.com/user-attachments/assets/489b6a3f-c34d-4a2b-a620-fe63768c7b82"> do you get the same error if you create another workspace? can you try `fedora 40 with openssh` for the base template?
kennethnym commented 2024-12-05 17:35:27 +00:00 (Migrated from github.com)

i am struggling to see why docker is not reporting the host port that is mapped to the container port even though it knows that port 22 is exposed on the container side.

https://github.com/kennethnym/tesseract/blob/master/internal/workspace/workspace_manager.go#L191-L199

i am struggling to see why docker is not reporting the host port that is mapped to the container port even though it knows that port 22 is exposed on the container side. https://github.com/kennethnym/tesseract/blob/master/internal/workspace/workspace_manager.go#L191-L199
ridhwaans commented 2024-12-05 20:40:05 +00:00 (Migrated from github.com)

the container looks like its running in Docker desktop
image
If i perform a create again, it asks me to rename the existing container to continue
image
If I try with a new workspace name, its back to the failed to bind ssh port toast error

do you have sshd daemon running on your host machine?
the app targets localhost in my case and I dont know if sshd is a required prerequisite

sudo systemctl status sshd
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

for me, sudo lsof -i :2222 returns nothing and port 2222 on the host is not mapped to port 22 inside the container
image

the container looks like its running in Docker desktop ![image](https://github.com/user-attachments/assets/f4088342-4fe5-4f4c-9524-1770ef0adfe7) If i perform a create again, it asks me to rename the existing container to continue ![image](https://github.com/user-attachments/assets/73327cfc-2ac1-47ec-b22e-535e6ea1c825) If I try with a new workspace name, its back to the failed to bind ssh port toast error do you have sshd daemon running on your host machine? the app targets localhost in my case and I dont know if sshd is a required prerequisite ``` sudo systemctl status sshd System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down ``` for me, `sudo lsof -i :2222` returns nothing and port 2222 on the host is not mapped to port 22 inside the container ![image](https://github.com/user-attachments/assets/d268b2d8-9701-40bc-a040-ddd5f0ef8122)
kennethnym commented 2024-12-07 11:37:34 +00:00 (Migrated from github.com)

no, on paper you don't need sshd on the host to have it working, but can you try starting sshd and see if it works?

no, on paper you don't need sshd on the host to have it working, but can you try starting sshd and see if it works?
kennethnym commented 2024-12-07 11:38:04 +00:00 (Migrated from github.com)

the issue here is that docker inspect is not returning the exposed port on host for some reason. i am still failing to understand why that's the case.

the issue here is that docker inspect is not returning the exposed port on host for some reason. i am still failing to understand why that's the case.
kennethnym commented 2024-12-07 11:38:52 +00:00 (Migrated from github.com)

can you also run docker version and paste the output here?

can you also run `docker version` and paste the output here?
ridhwaans commented 2024-12-07 21:39:10 +00:00 (Migrated from github.com)
docker version (on the host machine)
Client:
 Version:           27.3.1
 API version:       1.47
 Go version:        go1.22.7
 Git commit:        ce12230
 Built:             Fri Sep 20 11:39:44 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Desktop  ()
 Engine:
  Version:          27.3.1
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.22.7
  Git commit:       41ca978
  Built:            Fri Sep 20 11:41:11 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.21
  GitCommit:        472731909fa34bd7bc9c087e4c27943f9835f111
 runc:
  Version:          1.1.13
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
``` docker version (on the host machine) Client: Version: 27.3.1 API version: 1.47 Go version: go1.22.7 Git commit: ce12230 Built: Fri Sep 20 11:39:44 2024 OS/Arch: linux/amd64 Context: default Server: Docker Desktop () Engine: Version: 27.3.1 API version: 1.47 (minimum version 1.24) Go version: go1.22.7 Git commit: 41ca978 Built: Fri Sep 20 11:41:11 2024 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.7.21 GitCommit: 472731909fa34bd7bc9c087e4c27943f9835f111 runc: Version: 1.1.13 GitCommit: v1.1.13-0-g58aa920 docker-init: Version: 0.19.0 GitCommit: de40ad0 ```
ridhwaans commented 2024-12-07 22:18:50 +00:00 (Migrated from github.com)

it may be because Docker does not automatically bind a host port to a container port unless explicitly requested during container creation, and inspect.NetworkSettings.Ports is empty

Need to ensure that mgr.dockerClient.ContainerCreate includes -p or -P

sample:

// modified from https://github.com/kennethnym/tesseract/blob/master/internal/workspace/workspace_manager.go#L191-L199

inspect, err := mgr.dockerClient.ContainerInspect(ctx, res.ID)
if err != nil {
    return nil, err
}

ports, found := inspect.NetworkSettings.Ports[containerSSHPort]
if !found || len(ports) == 0 {
    return nil, errors.New("failed to bind SSH port for container")
}

hostPort := ports[0].HostPort
if hostPort == "" {
    return nil, errors.New("host port mapping is empty")
}

return hostPort, nil
it __may_ be_ because Docker does not automatically bind a host port to a container port unless explicitly requested during container creation, and `inspect.NetworkSettings.Ports` is empty Need to ensure that `mgr.dockerClient.ContainerCreate` includes `-p` or `-P` sample: ```go // modified from https://github.com/kennethnym/tesseract/blob/master/internal/workspace/workspace_manager.go#L191-L199 inspect, err := mgr.dockerClient.ContainerInspect(ctx, res.ID) if err != nil { return nil, err } ports, found := inspect.NetworkSettings.Ports[containerSSHPort] if !found || len(ports) == 0 { return nil, errors.New("failed to bind SSH port for container") } hostPort := ports[0].HostPort if hostPort == "" { return nil, errors.New("host port mapping is empty") } return hostPort, nil ```
Sign in to join this conversation.
No description provided.