colima icon indicating copy to clipboard operation
colima copied to clipboard

Cannot ctrl-c out of `columa nerdctl run`

Open hedefalk opened this issue 1 year ago β€’ 4 comments

Description

I'm using something like this:

colima start -p rosetta --arch aarch64 --cpu 4 --memory 8 --disk 60 --runtime containerd --vm-type vz --vz-rosetta --mount-type virtiofs

And when I start a container with nerdctl I cannot ctrl-c out of it:

> colima nerdctl -p rosetta -- run --rm -p 3000:3000 my_image

starting server
v20.17.0

  β–² Next.js 14.2.3
  - Local:        http://localhost:3000
  - Network:      http://0.0.0.0:3000

 βœ“ Starting...
 βœ“ Ready in 51ms
^C^C^C^C

My current workaround is to kill to use colima -p rosetta stop in another terminal. Am I missing something obvious here?

Version

🐟 colima version colima version 0.7.5 git commit: 1588c06

Operating System

  • [ ] macOS Intel <= 13 (Ventura)
  • [ ] macOS Intel >= 14 (Sonoma)
  • [ ] Apple Silicon <= 13 (Ventura)
  • [X] Apple Silicon >= 14 (Sonoma)
  • [ ] Linux

Output of colima status

🐟 colima -p rosetta status INFO[0000] colima [profile=rosetta] is running using macOS Virtualization.Framework INFO[0000] arch: aarch64
INFO[0000] runtime: containerd
INFO[0000] mountType: virtiofs

Reproduction Steps

  1. colima start -p rosetta --arch aarch64 --cpu 4 --memory 8 --disk 60 --runtime containerd --vm-type vz --vz-rosetta --mount-type virtiofs
  2. colima nerdctl -p rosetta -- run --rm any_image
  3. try to ctrl-c to exit.

Expected behaviour

I'm expecting ctrl-c to exit the nerdctl run

Additional context

No response

hedefalk avatar Sep 05 '24 19:09 hedefalk

How did you build my_image? And if you really want to interact with the shell, you should pass -it as additional flags.

I tried with some other docker images and I was able to interrupt with Ctrl + c.

abiosoft avatar Sep 06 '24 04:09 abiosoft

And if you really want to interact with the shell, you should pass -it as additional flags.

I don't, I just want to run in foreground and be able to ctrl-c when done.

I tried with some other docker images and I was able to interrupt with Ctrl + c.

I did too (with nginx) and you are right! So, definitely something with this image - BUT it is working to ctrl-c anyways from docker run. But there's something I'm missing because I still can't ctrl-c out of a simple image with colimas nerdctl.

A little better reproduction

I start two colima instances, one for docker and one for containerd:

colima start -p docker --arch aarch64 --cpu 4 --memory 8 --disk 10 --runtime docker --vm-type vz --vz-rosetta
colima start --arch aarch64 --cpu 4 --memory 8 --disk 10 --runtime containerd --vm-type vz --vz-rosetta

I create this very basic Dockerfile, sleep representing a service - I was trying out any differences between cmd/entrypoint, but that's probably a red herring:

FROM alpine as cmd
CMD echo 'Hello world' && sleep 30

FROM alpine as entrypoint
ENTRYPOINT echo 'Hello world' && sleep 30

Build them in both runtimes:

docker buildx build  . --target entrypoint -t entrypoint_service; docker buildx build . --target cmd -t command_service
nerdctl build . --target cmd -t command_service; nerdctl build . --target entrypoint -t entrypoint_service

For docker run, I can ctrl-c out of them with three ctrl-c's in a row:

docker run command_service
Hello world
^C^C^C
got 3 SIGTERM/SIGINTs, forcefully exiting

but not for nerdctl, I can't kill the container:

βœ— nerdctl run command_service
Hello world
^C^C^C^C^C^C^C^C

And I actually don't know a way other than actually stopping the vm with colima stop which takes a lot of time for me…

Maybe this is just upstream nerdctl? And probably I'm missing something obvious, because I CAN ctrl-c out of something like docker.io/nginx, but not my current "work image" (which is just a node process) nor these toy sleep-samples. I've been experimenting with ENTRYPOINT vs CMD because of that, but it seems unrelated.

Anyways, just thought I should report back with clearer repro. Any pointers are highly appreciated!

hedefalk avatar Sep 06 '24 09:09 hedefalk

Just wanted to make sure this was nothing around sleep vs a "real usecase" so here's another very standalone service:

FROM node:22
WORKDIR /usr/src/app
RUN echo '{ \
    "name": "standalone-node-server", \
    "version": "1.0.0", \
    "main": "server.js", \
    "dependencies": { \
    "express": "^4.17.1" \
    } \
    }' > package.json
RUN npm install
RUN echo 'const express = require("express"); \
    const app = express(); \
    const port = 3000; \
    app.get("/", (req, res) => res.send("Hello, World!")); \
    app.listen(port, () => console.log(`Server running on port ${port}`));' > server.js
EXPOSE 3000
CMD ["node", "server.js"]
docker buildx build . -t express_server
🐟 docker run express_server
Server running on port 3000
^C^C^C
got 3 SIGTERM/SIGINTs, forcefully exiting

nerdctl build . -t express_server
🐟 nerdctl run express_server
Server running on port 3000
^C^C^C^C^C^C^C^C^C^C

Running docker with -it flag by the way, makes it bad there too:

βœ— docker run -it express_server
Server running on port 3000
^C^C^C^C^C^C^C^C^C^C^C^C^C^C

I've been using docker desktop for mac previously and there it has always worked in all cases to do ctrl-c out of a foreground docker run. But again, it actually does work with some official images like "nginx" so possibly I can fix it in my Dockerfiles, but I can't currently figure out what's the culprit here…

hedefalk avatar Sep 06 '24 09:09 hedefalk

Huh, for docker the triple ctrl-c doesn't really stop the container, just the command.

🐟 docker run express_server
Server running on port 3000
^C^C^C
got 3 SIGTERM/SIGINTs, forcefully exiting
βœ— docker run express_server
Server running on port 3000
^C^C^C
got 3 SIGTERM/SIGINTs, forcefully exiting
βœ— docker ps
CONTAINER ID   IMAGE            COMMAND                  CREATED         STATUS         PORTS      NAMES
1437287fed07   express_server   "docker-entrypoint.s…"   5 seconds ago   Up 4 seconds   3000/tcp   unruffled_noether
e66742899713   express_server   "docker-entrypoint.s…"   8 seconds ago   Up 7 seconds   3000/tcp   determined_carver

hedefalk avatar Sep 06 '24 10:09 hedefalk