j8r / dockerfiles

Repository for my dockerfiles
https://hub.docker.com/u/jrei
ISC License
123 stars 46 forks source link

Windows Host: (jrei/systemd-ubuntu:18.04) Docker has stdout. Docker Compose doesn't. #14

Closed vellotis closed 3 years ago

vellotis commented 3 years ago

I'm struggling with getting systemd output with docker-compose. While executing with plain docker run I successfully get the stdout.

I'm guessing that it has something to do with https://github.com/moby/moby/issues/27202. But I may be wrong.

My dockerfile

FROM  jrei/systemd-ubuntu:18.04

RUN sed -i 's/#\(ForwardToConsole=\).*$/\1yes/' /etc/systemd/journald.conf

STOPSIGNAL SIGRTMIN+3

RUN printf '\
[Unit]\n\
Description=sleep & echo service\n\
\n\
[Service]\n\
ExecStart=/bin/sh -c "count=0; while true; do count=$(( $count + 1 )); echo \"x $count\"; sleep 2;  done"\n\
\n\
[Install]\n\
WantedBy=multi-user.target\
' >> /etc/systemd/system/echo-sleep.service && \
    systemctl enable echo-sleep.service

The following run command shows the stdout from the sleep & echo service.

docker build -t systemd-logging . &&
    docker run --name systemd-logging \
                      --security-opt seccomp=unconfined \
                      --tmpfs /tmp \
                      --tmpfs /run \
                      --tmpfs /run/lock \
                      -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
                      -t systemd-logging

The equivalent docker-compose setup doesn't show the output or even the systemd bootup entries.

version: "3.7"

services:

  systemd-logging:
    container_name: systemd-logging
    image: systemd-logging
    privileged: true
    logging:
      driver: "json-file"
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 8442:443
      - 2342:2345
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    security_opt:
      - seccomp:unconfined
    tmpfs:
      - /tmp
      - /run
      - /run/lock

and docker-compose up.

I have also tried to utilize CMD ["/bin/bash", "-c", "exec /sbin/init --log-target=journal 3>&1"] but without success.

I would be grateful if anybody would have any hunch on this problem. Thanks.

j8r commented 3 years ago

I can't help debug this, because not on Windows. Does this work on Linux?

vellotis commented 3 years ago

I tried it out on Ubuntu 20.10 host running on VMware Workstation 16 virtualization. The behavior is the same:

j8r commented 3 years ago

After some testing, adding tty: true fix the issue. It was the option missing compared to the docker run command, which has the -t (or --tty) option.