lima-vm / lima

Linux virtual machines, with a focus on running containers
https://lima-vm.io/
Apache License 2.0
15.39k stars 604 forks source link

Cannot access randomly selected port #527

Open kaskavalci opened 2 years ago

kaskavalci commented 2 years ago

When a container is started without host port, it is not accessible via lima.

$ docker run -d -p 80 nginx:alpine
aece04c330bd262ab2ab6b07bb8f30f41b5ce96aab2339ae743689ae093ccd88
$ docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED                  STATUS        PORTS                                     NAMES
aece04c330bd   nginx:alpine   "/docker-entrypoint.…"   Less than a second ago   Up 1 second   0.0.0.0:49198->80/tcp, :::49198->80/tcp   adoring_meninsky
$ curl localhost:49198
curl: (7) Failed to connect to localhost port 49198: Connection refused

It seems even though they are started with a specific host port, when that port was used before, it is still not available.

$ docker run -d -p 49200:80 nginx:alpine
dbd434293baa57f5c79b6260e2c0b800df90ee9bd46c2cf8ecc6ff1343cf588c
$ curl localhost:49200
curl: (7) Failed to connect to localhost port 49200: Connection refused
$ docker run -d -p 49300:80 nginx:alpine
ce99f09ba568d8d974bdd288fa03bf87797a2b23c32527d37490beb7ecd1ea02
$ curl --head localhost:49300
HTTP/1.1 200 OK
Server: nginx/1.21.5
Date: Thu, 06 Jan 2022 15:05:01 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 28 Dec 2021 18:48:00 GMT
Connection: keep-alive
ETag: "61cb5be0-267"
Accept-Ranges: bytes
AkihiroSuda commented 2 years ago

With rootful docker or rootless docker?

Could you provide the output of docker info (or just Lima yaml) and Lima version?

kaskavalci commented 2 years ago

I am using examples/docker so it seems it is rootless. I am using lima 0.8.0. Below is the docker info information.

$ docker info
Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 4
  Running: 0
  Paused: 0
  Stopped: 4
 Images: 3
 Server Version: 20.10.12
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: false
  userxattr: true
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  rootless
  cgroupns
 Kernel Version: 5.13.0-22-generic
 Operating System: Ubuntu 21.10
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 3.828GiB
 Name: lima-default
 ID: N6MU:UWCY:WKWO:OIUC:O26T:7ZHS:GT7K:YSHV:ZEZO:4W5H:5KAE:G7RK
 Docker Root Dir: /home/lima.linux/.local/share/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false