I wrote simple program that should print digits from 1 to 9 waiting 1 second between printing.
#!/usr/bin/env perl6
my $x = 1;
while $x < 10 {
say $x++;
sleep(1);
}
It works as expected when I run it from command line
Video 1
I was trying to achieve the same effect using docker container and program printed first digit, then froze on 9 seconds and printed rest of digits.
Video 2
My docker-compose
version: "3.1"
services:
cron:
build: phpdocker/cron
container_name: docker-perl6
volumes:
- ./cron:/cron
working_dir: /cron
command: "app.pl"
and Dockerfile
FROM jjmerelo/alpine-perl6
Versions
docker -v
Docker version 18.03.1-ce, build 9ee9f40
docker-compose -v
docker-compose version 1.15.0, build e12f3b9
perl6 -v
This is Rakudo version 2018.03-136-g768cf9f built on MoarVM version 2018.03-56-g85fc758
implementing Perl 6.c.
I changed say $x++;
to say "{time}: {$x++}";
docker-perl6 | 1527933936: 1
docker-perl6 | 1527933937: 2
docker-perl6 | 1527933938: 3
docker-perl6 | 1527933939: 4
docker-perl6 | 1527933940: 5
docker-perl6 | 1527933941: 6
docker-perl6 | 1527933942: 7
docker-perl6 | 1527933943: 8
docker-perl6 | 1527933944: 9
So as @elizabeth-mattijsen and @melpomene mentioned it is issue connected with buffering output by docker.
First, thanks for using my perl6 docker container. I will try a few things with your program, to find out what's really the problem. I gather you want to know, in general, what happens with these kind of programs in docker, and not in the particular docker-compose environment, right?
You can do this:
docker run -it --rm --entrypoint sh jjmerelo/alpine-perl6
and then create the file inside the container (use cat > con
for instance). I've tested it and it runs correctly, no problem at all.
You can do this:
docker run -it --rm -v $PWD:/app jjmerelo/alpine-perl6 /app/app.pl
Still no problem at all, it prints stuff one a second. It does not seem to be, by itself, a docker buffering problem. Let's try to go a bit further
What you are doing here is composing two docker containers, you are running one container from the other. We have pretty much established that alpine-perl6 might not have a problem. Could it be in phpdocker? My money is on that, although it's not clear which container are you using, this gist seems to point at that container actually using buffering. In the updated answer it's not really the time what makes it print, but the amount of bytes you are printing, good enough for filling the buffer. Try to change $x
to "a good amount of bytes, including $x"
to see if that's the case.
At any rate, I would look into the configuration of the phpdocker container as @lizmat says. Besides, if what you want is just cron, you can follow this advice, install cron for alpine, or use other containers such as this one
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With