abiosoft / caddy-docker

Docker container for Caddy
https://hub.docker.com/r/abiosoft/caddy/
MIT License
771 stars 315 forks source link

php - Uncaught Exception: Could not gather sufficient random data in Command line #57

Open ckeeney opened 7 years ago

ckeeney commented 7 years ago

PHP v7.0.16 has a bug that throws this error under certain conditions: https://github.com/docker-library/php/issues/376

I run into this error on my debian-based server:

ckeeney@staging $ cat /etc/issue
Debian GNU/Linux 8 \n \l
ckeeney@staging $ docker run --entrypoint=php abiosoft/caddy:php "-r random_int(0,1);"
PHP Fatal error:  Uncaught Exception: Could not gather sufficient random data in Command line code:1
Stack trace:
#0 Command line code(1): random_int(0, 1)
#1 {main}
  thrown in Command line code on line 1

I don't experience this problem on my Ubuntu-based laptop.

For quite a while, I've been thinking the php tag might be better built as FROM php:alpine. Installing Caddy is easy, it's just an executable. The way it is currently built restricts us to using exactly the version of PHP made available through the alpine repos.

When I built a container for Caddy with nodejs similar to the abiosoft/caddy:php image, I started from node:alpine and added Caddy. My nodejs + caddy Dockerfile looks something like this:

FROM node:7.2-alpine
RUN apk add --no-cache ack git curl
RUN npm install -g --progress=false \
    create-react-app serve yarn

# install caddy
ARG plugins=http.git
RUN curl --silent --show-error --fail --location \
    --header "Accept: application/tar+gzip, application/x-gzip, application/octet-stream" -o - \
    "https://caddyserver.com/download/linux/amd64?plugins=${plugins}" \
    | tar --no-same-owner -C /usr/bin/ -xz caddy \
    && chmod 0755 /usr/bin/caddy \
    && /usr/bin/caddy -version

WORKDIR /srv
COPY ./package.json /srv/package.json
COPY ./yarn.lock /srv/yarn.lock
RUN yarn
COPY . /srv
RUN yarn build
COPY ./Caddyfile /etc/Caddyfile
VOLUME /srv
EXPOSE 80
ENTRYPOINT ["/usr/bin/caddy"]
CMD ["--conf", "/etc/Caddyfile", "--log", "stdout"]
abiosoft commented 7 years ago

Thanks for the suggestion. Gonna try it out and see if it fixes this.

ckeeney commented 7 years ago

@abiosoft I can probably open a pull request for this this week. I am wary of this change though since changing the base image of the Dockerfile will likely introduce breaking changes.

abiosoft commented 7 years ago

You can send it in. The approach is simple. All version tagged images are not gonna be touched. e.g. abiosoft/caddy:php can be updated but abiosoft/caddy:0.10.2-php can not. The earliest it will get in is maybe abiosoft/caddy:0.10.3-php.

Also, if we can make it consistent. i.e. same Caddyfile works as expected, I do not think there should be issues.

Thanks.

ckeeney commented 7 years ago

Yes, I'm mostly referring to people who just track abiosoft/caddy:php instead of a specific version tag. I'll open a pull request later this week. I think this if we change the base image, we could maybe close #35, or at least discuss doing so. I think it's reasonable that this image only installs the default php extensions, which would be the case if we relied on php:fpm-alpine

abiosoft commented 7 years ago

Good point. I have some thoughts around the tags and should introduce new ones within the next few weeks.

Thinking of making the default more stable while introducing an edge tag.