Skip to content

failed to open stream: Cannot assign requested address #836

@muuvmuuv

Description

@muuvmuuv

I have set up a docker-compose with a nginx:1.15.12 server and php:7.3-fpm-stretch.

docker-compose.yml
version: '3.7'

services:
  nginx:
    image: localhost-nginx
    build: ./docker/nginx
    container_name: localhost-nginx
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - type: bind
        source: ./certs
        target: /etc/nginx/ssl
        read_only: true
      - type: bind
        source: ./www
        target: /var/www/localhost
        read_only: true
      - type: bind
        source: ./docker/nginx/components
        target: /etc/nginx/components
        read_only: true
      - type: bind
        source: ./docker/nginx/conf.d
        target: /etc/nginx/conf.d
        read_only: true
  php:
    image: localhost-php
    build: ./docker/php
    container_name: localhost-php
    volumes:
      - type: bind
        source: ./www
        target: /var/www/localhost
        read_only: true
      - type: bind
        source: ./docker/php/php.ini
        target: /usr/local/etc/php/php.ini
        read_only: true

  # MEMCACHED

  # MARIADB
docker/php/Dockerfile
FROM php:7.3-fpm-stretch

COPY share/entrypoint.sh    /usr/share/
COPY share/php-*.sh         /usr/share/
COPY php.ini                /usr/local/etc/php/php.ini
COPY conf.d/*               /usr/local/etc/php/conf.d/


# ┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
# Install packages

ENV pkg_dev "libpng-dev libicu-dev libzip-dev libbz2-dev"
ENV pkg_php ""

RUN printf "\n\e[96m>\e[0m\033[1m Install packages \e[0m\n\n" \
  # && php -i \
  && apt-get update \
  && apt-get install -qqy $pkg_dev $pkg_php \
  && echo "---"


# ┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
# Configure System

RUN printf "\n\e[96m>\e[0m\033[1m Configure System \e[0m\n\n" \
  && ln -fs /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
  && dpkg-reconfigure -f noninteractive tzdata \
  && chmod +x /usr/share/entrypoint.sh \
  && chmod +x /usr/share/php-*.sh \
  && pear config-set php_ini /usr/local/etc/php/php.ini \
  && pecl config-set php_ini /usr/local/etc/php/php.ini \
  && echo "---"


# ┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
# Configure php-fpm

# TODO: replace ACPU with docker memcached
RUN printf "\n\e[96m>\e[0m\033[1m Configure php-fpm \e[0m\n\n" \
  && pecl install apcu \
  && pecl install xdebug \
  && docker-php-ext-enable opcache \
  && docker-php-ext-install gd \
  && docker-php-ext-install bz2 \
  && docker-php-ext-install intl \
  && docker-php-ext-install zip \
  && docker-php-ext-install mysqli \
  && echo "---"


# ┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
# Cleaning

RUN printf "\n\e[96m>\e[0m\033[1m Cleaning \e[0m\n\n" \
  && apt-get purge -qqy $pkg_dev \
  && rm -rf /var/lib/apt/lists/* \
  && echo "---"

ENTRYPOINT ["/usr/share/entrypoint.sh"]

CMD ["php-fpm"]
docker/nginx/Dockerfile
FROM nginx:1.15.12

COPY share/entrypoint.sh    /usr/share/
COPY share/nginx-*.sh       /usr/share/

ENV TIMEZONE              Europe/Berlin
ENV NGINX_VERSION_SHORT   1.15.12


# ┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
# Install packages

ENV pkg_common ""

RUN printf "\n\e[96m>\e[0m\033[1m Install packages \e[0m\n\n" \
  && apt-get update \
  && apt-get install -qqy $pkg_common \
  && echo "---"


# ┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
# Configure System

RUN printf "\n\e[96m>\e[0m\033[1m Configure System \e[0m\n\n" \
  && ln -fs /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
  && dpkg-reconfigure -f noninteractive tzdata \
  && chmod +x /usr/share/entrypoint.sh \
  && chmod +x /usr/share/nginx-*.sh \
  && echo "---"


# ┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
# Configure NGINX

RUN printf "\n\e[96m>\e[0m\033[1m Configure NGINX \e[0m\n\n" \
  && unlink /var/log/nginx/access.log \
  && unlink /var/log/nginx/error.log \
  && touch /var/log/nginx/access.log \
  && touch /var/log/nginx/error.log \
  && chown nginx /var/log/nginx/*log \
  && chmod 644 /var/log/nginx/*log \
  && touch /var/run/nginx.pid \
  && chown -R 991:991 /var/run/nginx.pid \
  && echo "---"


# ┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
# Cleaning

RUN printf "\n\e[96m>\e[0m\033[1m Cleaning \e[0m\n\n" \
  && apt-get purge -qqy $pkg_common \
  && rm -rf /var/lib/apt/lists/* \
  && echo "---"


COPY conf.d/        /etc/nginx/conf.d/
COPY components/    /etc/nginx/components/
COPY nginx.conf     /etc/nginx/nginx.conf
COPY modules/*      /usr/lib/nginx/modules/

ENTRYPOINT ["/usr/share/entrypoint.sh"]

CMD ["nginx", "-g", "daemon off;"]

The server is running fine and also all plugin, no errors, but when I call file_get_contents in PHP I get this error:

Warning: file_get_contents(https://localhost/data/nav.json): failed to open stream: Cannot assign requested address in /var/www/localhost/partials/header.php on line 3
string(31) "https://localhost/data/nav.json" bool(false)

EDIT

Project can be found here: https://github.com/muuvmuuv/webserver

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionUsability question, not directly related to an error with the image

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions