Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

panpan's avatar

Laravel - Docker - Nginx - Behat

Hi, I am trying to run behat inside an Nginx container in a laravel app. My docker-compose.yml

version: '2'

services:
  load_balancer:
    image: tutum/haproxy
    links:
      - nginx
    ports:
      - "8888:80"

  nginx:
    image: andrewmclagan/nginx-hhvm
    volumes:
      - ./www:/var/www
      - ./sites:/etc/nginx/sites-enabled
    links:  
      - mysql:mysql
      - redis:predis
    networks:
      - front-tier
      - back-tier
    environment:
      - APP_ENV=local
      - DB_DATABASE=homestead
      - DB_PASSWORD=secret
      - DB_HOST=mysql

  artisan:
    image: spiralout/dartisan
    volumes:
      - ./www:/var/www
    links:
      - mysql:mysql
      - redis:predis
    networks:
      - front-tier
      - back-tier

  mysql:
    image: spiralout/alpine-mariadb
    ports:
      - "3306:3306"
    volumes:
      - ./database:/var/lib/mysql
    networks:
      - back-tier

  composer:  
    image: spiralout/dcomposer
    volumes:
      - ./www:/var/www
    networks:
      - back-tier

  nodejs:  
    image: spiralout/dnodejs
    volumes:
      - ./www:/var/www
    networks:
      - back-tier

  redis:
    image: spiralout/alpine-redis
    volumes:
      - ./redis-data:/data
    networks:
      - back-tier

volumes:
  www:
  sites:
  redis-data:

networks:
  front-tier:
  back-tier:

What I do after is

docker-compose up -d

and then

docker exec -it <nginx_name> \bin\bash

I then try to run behat

vendor/behat/behat/bin/behat

My test simply tries to visit and print the homepage. FeatureContext.php

<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;

/**
 * Defines application features from the specific context.
 */
class FeatureContext extends Behat\MinkExtension\Context\MinkContext implements Context, SnippetAcceptingContext
{
    /**
     * Initializes context.
     *
     * Every scenario gets its own context instance.
     * You can also pass arbitrary arguments to the
     * context constructor through behat.yml.
     */
    public function __construct()
    {
    }

    /**
     * @Given that I am on the homepage
     */
    public function thatIAmOnTheHomepage()
    {
        $this->iAmOnHomepage();
        $this->visit("https://localhost:80");
        $this->printLastresponse();
    }

    /**
     * @Given that name is :arg1
     */
    public function thatNameIs($arg1)
    {
        $this->fillField('name', $arg1);
    }

    /**
     * @Given that email is :arg1
     */
    public function thatEmailIs($arg1)
    {
        $this->fillField('email', $arg1);
    }

    /**
     * @When you try to register
     */
    public function youTryToRegister()
    {
        $this->pressButton('registerButton');
    }

    /**
     * @Then you remain on the homepage
     */
    public function youRemainOnTheHomepage()
    {
        assertUrlRegExp('http://localhost');
    }
}

The problems are that I can't access the web app, I only get nginx homepage And secondly my app trying to visit it just get's page not found. Any help appreciated.

0 likes
0 replies

Please or to participate in this conversation.