Attach TTY to container?

Hey all,

I’m trying to access the shell of a particular container and I get this:

What do I need to do to enable these? I have tty: true in my compose file… It doesn’t help. Other containers I run have the shell attached. This one does not. If I try “execute” - I get this error:

So stuck…

If you are ok with just using the QNAPs shell you can do

docker exec -it containernme sh

And you will have a shell environment on the container

Where do I execute that command? In an SSH shell?

you open a plain old shell (SSH command via CMD in windows or any SSH compatible console program like putty)

1 Like

Same error:

[jono@NA9D-NAS-3 ~]$ docker exec -it vikunja-vikunja-1 sh
OCI runtime exec failed: exec failed: unable to start container process: exec: "sh": executable file not found in $PATH: unknown
[jono@NA9D-NAS-3 ~]$

That’s why I am asking about something in Compose…

I guess the container has no shell then

I just tried this on uptime-kuma and it worked fine

Well, that’s what I am asking. How can I add a shell…

I just tried adding stdin_open: true and I am getting closer:

But still not able to get into the actual shell of the container.

So there’s no way to get to the shell? I’m trying to execute a command for my app to test something. Maybe through the docker exec command?

I’ll try that.

in docker compose file add the following two lines to access tty in CS gui

stdin_open: true
tty: true

I did that. Doesn’t make any difference…

strange, I am able to connect and run commands in a simple networking tool application

services:
  network-tools:
    image: 'jonlabelle/network-tools:latest'
    restart: unless-stopped
    container_name: network-tools
    stdin_open: true
    tty: true
    networks:
      - backendApps
      
networks:     
  backendApps:
    external: true

Could be your app doesnt offer a shell to interact with and you need to launch one using the Execute command.

pick which you want (bash/sh) and click on execute, you get a log in shell and you can run commands in it.

See if that helps at all.

When I try the execute console I get the error shown above.

that likely means they did not package a bash command in the docker image. So i don’t think you will be able to connect to it with a shell.

Did the /bin/sh work?

If the docker is opensource you may be able to see what programs are in the /bin path and run it as a command using the execute console.

Niether console worked. I wasn’t sure if there was a way to add it.

Here’s the issue: to execute a command inside the container, the command must EXIST inside the container image. If your image doesn’t HAVE a shell, there’s nothing for you to exec.

Now, you might be able to ADD a shell, but that requires knowing HOW the image was built. Luckily, this is an open source build. Here’s the Dockerfile:

From this, I can see it was built on Alpine Linux. SO, create a Dockerfile that uses your image as the base, and add bash to it.
FROM vikunja/vikunja
RUN apk add --no-cache bash

The build the new image:
docker build newimage

If you’re using a docker-compose file to bring your container up, you’ll need to change the image to “newimage” (or whatever you want to call it.) Then you can exec bash inside the container.

3 Likes

OK. Thanks. I’ll have to look into that. Makes things a little bit of a pain with updating and all. Might just ask on the Vikunja forum why no shell. Trying to run a diagnostic command.

Realistically, if all you’re trying to do is debug something, then adding a shell to do that could be considered part of the debugging process. It doesn’t have to be permanent…once you have your information, revert to the provided image and move on.

…of course, you’re likely to encounter something I run into more often than I’d like to admit: enabling debug fixes the problem. :slight_smile: