skip to Main Content

I have a docker-compose environment setup.
But inside service "Lumen" im trying to make a CURL request to the service itself.

However, the container can’t access itself from localhost:8000 OR lumen:8000??

When I call lumen:8000 from the service it just never returns a response and just keeps loading ( And the curl request is to a different url so no infinite loop )

In my Laravel controller I found the protocal, host and port to be: http://lumen:8000

I seems like Laravel can’t connect to itself, which I really need for my project.

I can connect to the Laravel from my own computer through localhost, but I need the Laravel to call it self.

Error message from Laravel controller after doing a CURL request:
Failed to connect to localhost port 8000 after 0 ms: Connection refused
Changing host to "lumen" just makes the request load infinite. No matter what page I try to connect to.

Docker-compose file:

version: "3.5"

services:
  lumen:
    expose: 
      - "8000"
    ports:
      - "8000:8000"
    volumes:
      - ./server:/var/www/html
      - ./server/vendor:/var/www/html/vendor/
    build: 
      context: server
      dockerfile: Dockerfile
    command: php -S lumen:8000 -t public
    restart: always
    privileged: true
    depends_on:
      - database
    networks:
      - database

  frontend:
    build:
      context: client
      dockerfile: Dockerfile
    volumes:
      - ./client/src:/app/src
    ports:
      - 3000:3000
    stdin_open: true
    #restart: always
    networks:
      - database

  # Database Service (Mysql)
  database:
    image: mysql:latest
    container_name: blogmoda_mysql
    environment:
      MYSQL_DATABASE: blogmoda-app
      MYSQL_USER: root
      MYSQL_PASSWORD: root
      MYSQL_ROOT_PASSWORD: root
    command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']
    ports:
      - "127.0.0.1:3306:3306"
    volumes:
      - db-data:/var/lib/mysql
    networks:
      - database

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: dev_phpmyadmin
    links:
      - database
    environment:
      PMA_HOST: database
      PMA_PORT: 3306
      PMA_ARBITRARY: 1
    restart: always
    depends_on: 
      - database
    ports:
      - 9001:80
    networks:
      - database

volumes:
  db-data:

# Networks to be created to facilitate communication between containers
networks:
  database:

Server dockerfile:

FROM php:8.1-fpm-alpine

RUN apk update && apk add bash

RUN apk add chromium

RUN apk add --no-cache zip libzip-dev
RUN docker-php-ext-configure zip
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo pdo_mysql 
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install opcache

WORKDIR /var/www/html/

RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer

COPY . .

RUN composer install --ignore-platform-req=ext-zip --ignore-platform-reqs

2

Answers


  1. I believe localhost should work. Assuming curl is installed in lumen, in your compose file under the lumen service can you try changing your command

    command: php -S lumen:8000 -t public
    

    to a direct curl via bash as

    command: sh -c "curl -s localhost:8000"
    

    Then check the logs of the lumen container to see whether or not the curl ran successfully.

    Login or Signup to reply.
  2. Try 0.0.0.0:8000 instead localhost:8000. It works for localhost too

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search