swoole.Dockerfile 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. FROM php:7.4.1-alpine3.10
  2. MAINTAINER Alejandro Celaya <alejandro@alejandrocelaya.com>
  3. ENV APCU_VERSION 5.1.18
  4. ENV APCU_BC_VERSION 1.0.5
  5. ENV INOTIFY_VERSION 2.0.0
  6. ENV SWOOLE_VERSION 4.4.12
  7. RUN apk update
  8. # Install common php extensions
  9. RUN docker-php-ext-install pdo_mysql
  10. RUN docker-php-ext-install iconv
  11. RUN docker-php-ext-install calendar
  12. RUN apk add --no-cache oniguruma-dev
  13. RUN docker-php-ext-install mbstring
  14. RUN apk add --no-cache sqlite-libs
  15. RUN apk add --no-cache sqlite-dev
  16. RUN docker-php-ext-install pdo_sqlite
  17. RUN apk add --no-cache icu-dev
  18. RUN docker-php-ext-install intl
  19. RUN apk add --no-cache libzip-dev zlib-dev
  20. RUN docker-php-ext-install zip
  21. RUN apk add --no-cache libpng-dev
  22. RUN docker-php-ext-install gd
  23. RUN apk add --no-cache postgresql-dev
  24. RUN docker-php-ext-install pdo_pgsql
  25. # Install APCu extension
  26. ADD https://pecl.php.net/get/apcu-$APCU_VERSION.tgz /tmp/apcu.tar.gz
  27. RUN mkdir -p /usr/src/php/ext/apcu\
  28. && tar xf /tmp/apcu.tar.gz -C /usr/src/php/ext/apcu --strip-components=1
  29. # configure and install
  30. RUN docker-php-ext-configure apcu\
  31. && docker-php-ext-install apcu
  32. # cleanup
  33. RUN rm /tmp/apcu.tar.gz
  34. # Install APCu-BC extension
  35. ADD https://pecl.php.net/get/apcu_bc-$APCU_BC_VERSION.tgz /tmp/apcu_bc.tar.gz
  36. RUN mkdir -p /usr/src/php/ext/apcu-bc\
  37. && tar xf /tmp/apcu_bc.tar.gz -C /usr/src/php/ext/apcu-bc --strip-components=1
  38. # configure and install
  39. RUN docker-php-ext-configure apcu-bc\
  40. && docker-php-ext-install apcu-bc
  41. # cleanup
  42. RUN rm /tmp/apcu_bc.tar.gz
  43. # Load APCU.ini before APC.ini
  44. RUN rm /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini
  45. RUN echo extension=apcu.so > /usr/local/etc/php/conf.d/20-php-ext-apcu.ini
  46. # Install inotify extension
  47. ADD https://pecl.php.net/get/inotify-$INOTIFY_VERSION.tgz /tmp/inotify.tar.gz
  48. RUN mkdir -p /usr/src/php/ext/inotify\
  49. && tar xf /tmp/inotify.tar.gz -C /usr/src/php/ext/inotify --strip-components=1
  50. # configure and install
  51. RUN docker-php-ext-configure inotify\
  52. && docker-php-ext-install inotify
  53. # cleanup
  54. RUN rm /tmp/inotify.tar.gz
  55. # Install swoole
  56. # First line fixes an error when installing pecl extensions. Found in https://github.com/docker-library/php/issues/233
  57. RUN apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS && \
  58. pecl install swoole-${SWOOLE_VERSION} && \
  59. docker-php-ext-enable swoole && \
  60. apk del .phpize-deps
  61. # Install composer
  62. RUN php -r "readfile('https://getcomposer.org/installer');" | php
  63. RUN chmod +x composer.phar
  64. RUN mv composer.phar /usr/local/bin/composer
  65. # Make home directory writable by anyone
  66. RUN chmod 777 /home
  67. VOLUME /home/shlink
  68. WORKDIR /home/shlink
  69. # Expose swoole port
  70. EXPOSE 8080
  71. CMD \
  72. # Install dependencies if the vendor dir does not exist
  73. if [[ ! -d "./vendor" ]]; then /usr/local/bin/composer install ; fi && \
  74. # When restarting the container, swoole might think it is already in execution
  75. # This forces the app to be started every second until the exit code is 0
  76. until php ./vendor/bin/mezzio-swoole start; do sleep 1 ; done