I'm trying to run my frontend tests on Docker (node:8.15-alpine) using Chromium and Karma, however I'm getting lots of ChromeHeadless related errors.
These tests used to work but recently they suddenly stopped, so I'm guessing it's either related to a third-party dependency (apk?), or the local Docker install.
I've created a branch on the repo with an easy to run command which reproduces the issue. README.md here:
https://github.com/olivercaine/react-redux-starter-kit-extended/tree/bug/cant-run-unit-tests-in-docker
Any help with this would be masively appreciated!
Thanks.
Expected Outcome:
[output of passed tests...]
Finished in 0.026 secs / 0.031 secs # 19:53:44 GMT+1100 (AEDT)
SUMMARY:
✔ 46 tests completed
Actual Outcome:
13 02 2020 09:10:45.314:ERROR [launcher]: Cannot start ChromeHeadless
13 02 2020 09:10:45.316:ERROR [launcher]: ChromeHeadless stdout:
13 02 2020 09:10:45.317:ERROR [launcher]: ChromeHeadless stderr:
13 02 2020 09:10:45.772:ERROR [launcher]: Cannot start ChromeHeadless
13 02 2020 09:10:45.772:ERROR [launcher]: ChromeHeadless stdout:
13 02 2020 09:10:45.773:ERROR [launcher]: ChromeHeadless stderr:
13 02 2020 09:10:45.939:ERROR [launcher]: Cannot start ChromeHeadless
13 02 2020 09:10:45.939:ERROR [launcher]: ChromeHeadless stdout:
13 02 2020 09:10:45.939:ERROR [launcher]: ChromeHeadless stderr:
13 02 2020 09:10:46.424:ERROR [launcher]: ChromeHeadless failed 2 times (cannot start). Giving up.
Finished in 0 secs / 0 secs # 09:10:46 GMT+0000 (UTC)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-redux-starter-kit#3.0.1 test: `cross-env NODE_ENV=test karma start build/karma.config`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-redux-starter-kit#3.0.1 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-02-13T09_10_46_935Z-debug.log
Update:
The above URL has been removed, however the full (now working) repo can be found here:
https://github.com/olivercaine/react-redux-starter-kit-extended/tree/modpack/latest
It seems there are some issues regarding the node:8-alpine image that you are using. See https://github.com/puppeteer/puppeteer/issues/379. I don't know if it's the same issue but I was able to run your tests using the node:8.15-slim as the base image of your base Dockerfile
You'll need to update your dev Dockerfile as well:
FROM olliecaine/base:master
WORKDIR /project
# Install Chrome
RUN apt update && apt install -y chromium
Ideally you would add ENV CHROME_BIN=/usr/bin/chromium to this Dockerfile, but for some reason this is not setting the variable properly.
To check that yourself, and insert console.log(process.env.CHROME_BIN) at the beginning of your build/karma.config.js file, you will see the value is still /usr/bin/chromium-browser when running the tests.
As a workaround, I had to insert this line at the beginning of the build/karma.config.js file:
process.env.CHROME_BIN = '/usr/bin/chromium'
Let me know if you understand why the ENV instruction is not working, I'm interested.
Thanks Baptiste, your answer helped me verify the fix was working.
Basically what I ended up doing was using a different URL for alpinelinux.org.
In the end I changed the Dockerfile to:
FROM node:8.15-alpine
WORKDIR /project
# Install Chrome
RUN echo http://dl-cdn.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories \
&& echo http://dl-cdn.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories \
&& echo http://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories \
&& apk --no-cache update && apk --no-cache upgrade \
&& apk add --no-cache chromium \
&& rm -rf /var/cache/apk/* /tmp/*
ENV CHROME_BIN /usr/bin/chromium-browser
which seemed to set the CHROME_BIN env variable properly, allowing me to run my tests in the Alpine container. Also meant I didn't need to update the karma.config.js file either. Previously I was using nl.alpinelinux.org/alpine/v3.8/ instead of edge.
Cheers for your help!
Related
I want to run some cron jobs in a Docker container and send the output to stdout. I read this post: How to run a cron job inside a docker container?
To try this out with a simple example, I created a demo crontab:
my-crontab:
* * * * * date > /dev/stdout 2> /dev/stderr
# empty line
Then I run an interactive shell inside a Docker container based on the image my scripts will need:
docker run -it --entrypoint bash python:3.10.3-bullseye
/# apt update
/# apt install cron
/# crontab < my-crontab
/# cron -f
If I wait 60 seconds, I expect to see some output to the console attached to the container once every minute. But there is no output.
Finally, I found the output in /var/spool/mail/mail. Here is one message:
From root#5e3c82cb3651 Tue May 10 20:04:02 2022
Return-path: <root#5e3c82cb3651>
Envelope-to: root#5e3c82cb3651
Delivery-date: Tue, 10 May 2022 20:04:02 +0000
Received: from root by 5e3c82cb3651 with local (Exim 4.94.2)
(envelope-from <root#5e3c82cb3651>)
id 1noW5S-0000SA-0T
for root#5e3c82cb3651; Tue, 10 May 2022 20:04:02 +0000
From: root#5e3c82cb3651 (Cron Daemon)
To: root#5e3c82cb3651
Subject: Cron <root#5e3c82cb3651> date > /dev/stdout 2> /dev/stderr
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <E1noW5S-0000SA-0T#5e3c82cb3651>
Date: Tue, 10 May 2022 20:04:02 +0000
Tue May 10 20:04:01 UTC 2022
Then it looks like /bin/sh is completely ignoring the shell redirection in the crontab.
#DavidMaze answered this in his comment (above - can't find a link to it). Redirecting to /proc/1/fd/1 and /proc/1/fd/2 (for stderr) totally works. Thank you, David.
Nevertheless, that's counterintuitive. The filesystem nodes /dev/stdout and /dev/stderr already exist as symlinks that point to /proc/1/fd/1 and /proc/1/fd/2, respectively, independent of cron. Why wouldn't cmd > /dev/stdout and cmd > /proc/1/fd/1 be interchangeable in a crontab?
cron was written quite a while a ago. And expectedly, it's not, say, docker-friendly. It expects tasks to produce no output. And if they do, that is considered an error, and cron tries to email the responsible person about it. There are some tricks to make cron tasks' output to be seen in docker logs, but why not choose a docker-friendly cron implementation?
One of which is supercronic:
docker-compose.yml:
services:
supercronic:
build: .
command: supercronic crontab
Dockerfile:
FROM alpine:3.17
RUN set -x \
&& apk add --no-cache supercronic shadow \
&& useradd -m app
USER app
COPY crontab .
crontab:
* * * * * date
A gist with a bit more info.
Another good one is yacron, but it uses YAML.
ofelia can be used, but they seem to focus on running tasks in separate containers. Which is probably not a downside, but I'm not sure why I'd want to do that.
But if you insist on traditional ones, you can find a couple in my other answer.
I have a Docker container, that runs the redis:6 image, which builds FROM debian:bullseye-slim. When starting the redis server, I load a shared object file as a module, called redisearch.so. On my new Mac M1Pro Monterey this fails, telling me the file does not exist, even though it clearly does. I have checked that the file is there and made sure the permission is 777 and ownership is root.
On my old mac and another Linux device it runs fine.
Does anyone have a clue what could be the problem here?
Dockerfile
############ COMPILING OUR REDISSEARCH EXTENSION
FROM debian:buster-slim AS builder
RUN apt-get update
RUN apt-get install -y git
RUN apt-get install -y libatomic1
RUN apt-get install -y cmake
WORKDIR /home
RUN git clone https://github.com/RediSearch/RediSearch.git
WORKDIR /home/RediSearch
RUN rm ./tests/ctests/ext-example/*
COPY ./redisearch-ext/ ./tests/ctests/ext-example/
WORKDIR ./tests/ctests/ext-example/
RUN make jurata_extension.so
############ GETTING THE REDISEARCH SHARED OBJECT FILE AND PUTTING IT ON A REDIS SERVER
# Openshift compatible version of redissearch
FROM redislabs/redisearch:1.6.14 as redisearch
FROM redis:6
# ENV LD_LIBRARY_PATH /usr/lib/redis/modules
RUN apt-get update
RUN apt-get install -y sudo
COPY --from=redisearch /usr/lib/redis/modules/redisearch.so /usr/lib/redis/modules/
COPY --from=builder home/RediSearch/tests/ctests/ext-example/jurata_extension.so ./
COPY --from=builder home/RediSearch/tests/ctests/ext-example/jurata_extension.so /usr/lib/redis/modules/
ADD container-entrypoint.sh /
EXPOSE 6379
CMD ls -l /usr/lib/redis/modules/redisearch.so; sudo /usr/local/bin/redis-server --loadmodule /usr/lib/redis/modules/redisearch.so
Log Output
-rwxr-xr-x 1 root root 8531584 Sep 6 2020 /usr/lib/redis/modules/redisearch.so
10:C 04 Nov 2021 10:01:02.540 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
10:C 04 Nov 2021 10:01:02.540 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=10, just started
10:C 04 Nov 2021 10:01:02.540 # Configuration loaded
10:M 04 Nov 2021 10:01:02.540 * monotonic clock: POSIX clock_gettime
10:M 04 Nov 2021 10:01:02.540 * Running mode=standalone, port=6379.
10:M 04 Nov 2021 10:01:02.540 # Server initialized
10:M 04 Nov 2021 10:01:02.541 # Module /usr/lib/redis/modules/redisearch.so failed to load: /usr/lib/redis/modules/redisearch.so: cannot open shared object file: No such file or directory
10:M 04 Nov 2021 10:01:02.541 # Can't load module from /usr/lib/redis/modules/redisearch.so: server aborting
So I am pretty new into creating containers and I have the simple Dockerfile where I would like to run a simple python script every minute:
FROM python:3.8-buster
RUN apt-get update && apt-get install -y cron
COPY my_python /bin/my_python
COPY root /var/spool/cron/crontabs/root
RUN chmod +x /bin/my_python
CMD cron -l 2 -f
where my_python:
print("hi world!!")
and root:
* * * * * python3 /bin/my_python
then I just create the image and the container:
docker image build -t python-test
docker container run -it --name python-test python-test
I was supposed to see every minute a print with the hi world, however when running the container ( after the image build) no logs seem to appear.
What am i doing wrong?
First, I believe you want -L 2 rather than -l 2 in your cron command line; see the man page for details.
The cron daemon logs to syslog, so if something isn't work as intended, it's a good idea to arrange to receive those messages. The busybox tool provides a simple syslog daemon that can log to an in-memory buffer and a tool for reading those logs, so I modified your Dockerfile to look like this:
FROM python:3.8-buster
RUN apt-get update && apt-get install -y cron busybox
COPY my_python /bin/my_python
COPY root /var/spool/cron/crontabs/root
RUN chmod +x /bin/my_python
CMD busybox syslogd -C; cron -L 2 -f
After starting this, I docker exec'd into the container and ran busybox logread and found:
Jan 24 16:50:45 7f516db86417 cron.info cron[4]: (CRON) INFO (pidfile fd = 3)
Jan 24 16:50:45 7f516db86417 cron.info cron[4]: (root) INSECURE MODE (mode 0600 expected) (crontabs/root)
Jan 24 16:50:45 7f516db86417 cron.info cron[4]: (CRON) INFO (Running #reboot jobs)
So there's your problem: the permissions on the root crontab are incorrect. There are two ways to fix this problem:
We could explicitly chmod the file when we copy it into place, or
We can use the crontab command to install the file, which takes care of that for us
I like option 2 because it means we don't need to know the specifics of what cron expects in terms of permissions. That gets us:
FROM python:3.8-buster
RUN apt-get update && apt-get install -y cron busybox
COPY my_python /bin/my_python
COPY root /tmp/root.crontab
RUN crontab /tmp/root.crontab
RUN chmod +x /bin/my_python
CMD busybox syslogd -C; cron -L 2 -f
With that change, we can confirm that the cron job is now running as expected:
Jan 24 16:59:50 8aa688ad31cc syslog.info syslogd started: BusyBox v1.30.1
Jan 24 16:59:50 8aa688ad31cc cron.info cron[4]: (CRON) INFO (pidfile fd = 3)
Jan 24 16:59:50 8aa688ad31cc cron.info cron[4]: (CRON) INFO (Running #reboot jobs)
Jan 24 17:00:01 8aa688ad31cc authpriv.err CRON[7]: pam_env(cron:session): Unable to open env file: /etc/default/locale: No such file or directory
Jan 24 17:00:01 8aa688ad31cc authpriv.info CRON[7]: pam_unix(cron:session): session opened for user root by (uid=0)
Jan 24 17:00:02 8aa688ad31cc cron.info CRON[7]: (root) END (python3 /bin/my_python)
Jan 24 17:00:02 8aa688ad31cc authpriv.info CRON[7]: pam_unix(cron:session): session closed for user root
But...there's still no output from the container! If you read through that man page, you'll find this:
cron then wakes up every minute, examining all stored crontabs,
checking each command to see if it should be run in the current
minute. When executing commands, any output is mailed to the owner of
the crontab (or to the user named in the MAILTO environment
variable in the crontab, if such exists)...
In other words, cron collects the output from programs and attempts
to mail to the user who owns the cron job. If you want to see the
output from the cron job on the console, you will need to explicitly
redirect stdout, like this:
* * * * * python3 /bin/my_python > /dev/console
With this change in place, running the image results in the message...
hi world!
...printing to the console once a minute.
I'm trying to run docker container with ubuntu and nodejs to run some node application.
Firstly, I've searched for similar error of mine, and all didn't work for me.
For example, command below also have failed.
FROM ubuntu:18.04 as osbuild
RUN rm -rf /var/lib/apt/lists/* && \
apt-get clean && \
apt-get -y update && \
This is not my first time to use this Dockerfile (I almostly reused it), but it fails and I'm so confused.
I'm guessing problem might be update on bionic-things in Ubuntu 18.04 (Just yesterday night... suspicious), or maybe it is problem of docker for mac, but I don't see any possible solution for this problem.
I'm using macOS 10.14.6 and Docker 19.03.4
My Dockerfile is
FROM ubuntu:18.04 as osbuild
RUN apt-get -y update && \
...
It failed with following error message:
Err:14 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages
Hash Sum mismatch
...
Last modification reported: Sat, 09 Nov 2019 01:06:44 +0000
Release file created at: Sat, 09 Nov 2019 01:05:59 +0000
There was update on Ubuntu dist, including my problem dir.
Update was done at 2019-11-10 19:18, and now I can build docker image without error.
I have this simple Dockerfile for testing, but this is also same in my LEMP stack in a PHP image: cron jobs simply not being executed in Docker.
This is my testing Dockerfile:
FROM debian:latest
MAINTAINER XY <info#domain.com>
LABEL Description="Cron" Vendor="Istvan Lantos" Version="1.0"
RUN apt-get -y update && apt-get -y dist-upgrade \
&& apt-get -y install \
cron \
rsyslog \
vim
RUN rm -rf /var/lib/apt/lists/*
#cron fixes
RUN touch /etc/crontab /etc/cron.d/* /var/spool/cron/crontabs/*
#COPY etc/cron.d /etc/cron.d
COPY etc/crontab /etc/crontab
#COPY var/spool/cron/crontabs /var/spool/cron/crontabs
RUN chmod 600 /etc/crontab /etc/cron.d/* /var/spool/cron/crontabs/*
RUN touch /etc/crontab /etc/cron.d/* /var/spool/cron/crontabs/*
RUN rm -rf /var/lib/apt/lists/*
COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
CMD ["/docker-entrypoint.sh"]
docker-entrypoint.sh:
#!/bin/bash
set -e
echo PID1 > /dev/null
/etc/init.d/rsyslog start
#Stay in foreground mode, don’t daemonize.
/usr/sbin/cron -f
And this is the Crontab file. I also placed one liners in /etc/cron.d or /var/spool/cron/crontabs with the name of the user, but the effect was the same just like if I modified this base crontab file: cron jobs not will be executed:
MAILTO=""
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/php7/bin:/usr/local/php7/sbin
# m h dom mon dow user command
#17 * * * * root cd / && run-parts --report /etc/cron.hourly
#25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
#47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
#52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
*/1 * * * * root date >> /var/log/cron-test.log 2>&1
This is the output of the /var/log/syslog file:
Jan 23 09:38:39 1ab854e8d9a7 rsyslogd: [origin software="rsyslogd" swVersion="8.4.2" x-pid="14" x-info="http://www.rsyslog.com"] start
Jan 23 09:38:39 1ab854e8d9a7 rsyslogd: imklog: cannot open kernel log(/proc/kmsg): Operation not permitted.
Jan 23 09:38:39 1ab854e8d9a7 rsyslogd-2145: activation of module imklog failed [try http://www.rsyslog.com/e/2145 ]
Jan 23 09:38:39 1ab854e8d9a7 cron[19]: (CRON) INFO (pidfile fd = 3)
Jan 23 09:38:39 1ab854e8d9a7 cron[19]: (*system*) NUMBER OF HARD LINKS > 1 (/etc/crontab)
Jan 23 09:38:39 1ab854e8d9a7 cron[19]: (*) ORPHAN (no passwd entry)
Jan 23 09:38:39 1ab854e8d9a7 cron[19]: (CRON) INFO (Running #reboot jobs)
/var/log/cron-test.log won't be created by the cron job.
I have a question for those who flagged this as "off topic" and SuperUser material, plus this is about general computing HARDWARE AND SOFTWARE: really? Docker questions when become sysadmin stuff? This way every Docker related question here have at least one flag. I'm not against promoting more users to the less known child sites, but we have more change to get the answer here than their.
UPDATE:
This is what I come up with until cron jobs not working:
End of Dockerfile:
COPY cron-jobs.sh /
RUN chmod +x /cron-jobs.sh
COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
CMD ["/docker-entrypoint.sh"]
docker-entrypoint.sh:
#!/bin/bash
set -e
echo PID1 > /dev/null
# Run script in the background (this is not daemonized)
/cron-jobs.sh &
/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
cron-jobs.sh:
#!/bin/bash
while true; do
date >> /var/log/cron-test.log 2>&1
sleep 60
done
Cron (at least in Debian) does not execute crontabs with more than 1 hardlink, see bug 647193. As Docker uses overlays, it results with more than one link to the file, so you have to touch it in your startup script, so the link is severed:
touch /etc/crontab /etc/cron.*/*