5

Just starting to learn containers so I probably have missed something / not read enough yet, but I have run into a strange behavior and am trying to understand what is happening. I tried googling but haven't been able to find an explanation so I can't tell if I am missing some concepts, running into a some limitation, or encountering a bug.

Basically, when I try to attach to a container, the container stops.

I'm on Fedora 33 using podman v3.1.2 installed from central repos and following the official "Getting Started" guide (here). I am running everything in user-mode (e.g. rootless).

A summary of the initial commands run from the guide:

$ podman pull docker.io/library/httpd >/dev/null
$ podman run -dt -p 8080:80/tcp docker.io/library/httpd
  48cf6fbe988a6feb243c62e5298b37f51709251cc05f8d39f17566e1d7fc17f7
 
$ podman ps
  CONTAINER ID  IMAGE                    COMMAND           CREATED         STATUS             PORTS                 NAMES
  48cf6fbe988a  docker.io/library/httpd  httpd-foreground  23 seconds ago  Up 22 seconds ago  0.0.0.0:8080->80/tcp  cool_cori
 
$ curl http://localhost:8080
  <html><body><h1>It works!</h1></body></html>
$ podman stop -l
  48cf6fbe988a6feb243c62e5298b37f51709251cc05f8d39f17566e1d7fc17f7
$ podman rm -l
  48cf6fbe988a6feb243c62e5298b37f51709251cc05f8d39f17566e1d7fc17f7

So far so good. Now I was trying to move on from the guide just a little. I wanted to see if I could name the container and also attach to it and run a bash terminal from within the container. I skimmed through man podman-run and added the --name and --hostname parameters which seems to be fine. Also read through man podman-attach and it sounds like it should allow me to get a bash terminal in the container but when I use it, it stops the container.

$ podman run -dt --name "mycontainer" --hostname "testbox" -p 8081:80/tcp docker.io/library/httpd
  77e74e729ac0dd86ed5a58aa3481909148de9017ffc52b327f7e69f74da22549
 
$ curl http://localhost:8081
  <html><body><h1>It works!</h1></body></html>
 
$ podman attach mycontainer
 
$ podman ps
  CONTAINER ID  IMAGE   COMMAND  CREATED  STATUS  PORTS   NAMES
 
$ podman start mycontainer
 
$ podman ps
  CONTAINER ID  IMAGE                    COMMAND           CREATED        STATUS            PORTS                 NAMES
  77e74e729ac0  docker.io/library/httpd  httpd-foreground  2 minutes ago  Up 8 seconds ago  0.0.0.0:8081->80/tcp  mycontainer
 
$ curl http://localhost:8081
  <html><body><h1>It works!</h1></body></html>
 
$ podman attach mycontainer
  [Fri Jul 02 23:35:04.479855 2021] [mpm_event:notice] [pid 1:tid 140188888724608] AH00492: caught SIGWINCH, shutting down gracefully
 

So is this a bug? Otherwise, what am I doing wrong / why is it behaving this way? Apologies if this is something stupid due to gaps in my knowledge. Also not sure why it stops silently the first time I try attaching to it but it prints a message the next time.

I tried googling the error and got 3 results. One was in Chinese and the other 2 didn't look relevant to my situation. I also turned off SELinux via /etc/selinux/config and rebooted but that didn't make any difference.

Edit: also to clarify, I am using defaults. I have not done anything special for either podman, the image, or the container beyond what is shown in the commands. I do have the cockpit package installed as well but am not using it yet.

1
  • Note: Similar question which of course I couldn't find when I needed it but ended up coming across several days later while looking up something else lol. This one is for docker of course, but all the commands should still be relevant for podman. Figured I'd post it as a comment off my original post for future googlers (although personally I think AB did a better job of actually describing why this happens) stackoverflow.com/questions/45638784/…
    – zpangwin
    Jul 6, 2021 at 2:43

1 Answer 1

5

You are trying to get interactive control of the running process. As the container was run with the -t option, apache is attached to a terminal, something not meant to be for a daemon. Attaching to its terminal triggers a Window Change/Resize signal: SIGWINCH. Apache interprets this as the signal it reserves to be asked a graceful shutdown: container stops.

You should probably do this instead:

  • run the daemon as a daemon (no -t)

    podman run -d --name "mycontainer" --hostname "testbox" -p 8081:80/tcp docker.io/library/httpd
    
  • replace podman attach with podman exec

    NAME

    podman-attach - Attach to a running container

    [...]

    DESCRIPTION The attach command allows you to attach to a running container using the container's ID or name, either to view its ongoing output or to control it interactively.

    vs

    NAME

    podman-exec - Execute a command in a running container

    [...]

    DESCRIPTION

    podman exec executes a command in a running container.

    $ podman exec -it mycontainer bash
    root@testbox:/usr/local/apache2# ps -ef
    bash: ps: command not found
    root@testbox:/usr/local/apache2# ls -l /proc/1/exe
    lrwxrwxrwx 1 root root 0 Jul  3 11:50 /proc/1/exe -> /usr/local/apache2/bin/httpd
    root@testbox:/usr/local/apache2# 
    
1
  • Thanks! I was half suspecting it might be related to what I was running in the container (apache) but wasn't really sure what other good demo containers to try for this that wouldn't potentially lead me off on other issues. I'll have to read up about why the Ctrl+p,Ctrl+q combo thing didn't work for exiting podman exec like the man page stated but luckily just doing exit from bash got my back to my (host) terminal and then podman ps , I saw my container was still running. This was a huge help!
    – zpangwin
    Jul 4, 2021 at 4:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .