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

thewebdevelopers's avatar

CircleCI + Docker + Dusk + Hostname

I've set up some Dusk tests which run great locally, but fail when using Docker within CircleCI. The error I receive is a straightforward one;

  1. Tests\Browser\HomeTest::check_home_contains_text Did not see expected text [Home] within element [body]. Failed asserting that false is true.

Through investigation, it seems as though Dusk is hitting the correct URL, however it's failing to assert so Docker mustn't be resolving my.site to the Laravel install. I've added 127.0.0.1 my.site to the hosts file as per the CircleCI config below.

My assumption is that I need to configure a virtual host to point to ~/laravel/public, however a number of attempts to set up the config for this fail. Can somebody advise how this can be achieved? I don't believe the Docker images from CircleCI come bundled with nginx or Apache, would installing one of these be the way to go, and if so is there somebody out there with a public repository or some info on how to go about this?

Please note, I cannot simply use localhost as I have a subdomain/alias with routes and check domain within my routes/web.php

CircleCI config.yml:

# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
  build:
    docker:
      # CircleCI Docker Images: https://circleci.com/docs/2.0/circleci-images/
      # PHP 7.1 and MySQL 5.7.19
      - image: circleci/php:7.1-browsers
      - image: circleci/mysql:5.7.19
        environment:
            MYSQL_DATABASE: mysite_testing
            MYSQL_USER: mysite
            MYSQL_PASSWORD: mysite
        command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']

    working_directory: ~/laravel

    steps:
      # Checkout branch
      - checkout

      - run:
         name: Install System Dependencies
         command: |
            sudo apt-get install -y libzip-dev mysql-client
            sudo apt-get install -y libsqlite3-dev libnss3 libgconf-2-4 libfontconfig1 chromium xvfb

      - run:
         name: Install PHP extensions
         command: sudo docker-php-ext-install pdo_mysql zip

      - run:
         name: Wait on MySQL
         command: dockerize -wait tcp://localhost:3306 -timeout 1m

      # Set up Laravel .env file
      - run:
         name: Setup Laravel testing environment variables for CircleCI test
         command: cp .env.testing .env

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "composer.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      # Install Composer packages
      - run: composer install -n --prefer-dist

      - save_cache:
          paths:
            - ./vendor
          key: v1-dependencies-{{ checksum "composer.json" }}

      # Run PHPUnit tests
      - run:
          name: Run PHPUnit tests
          command: ./vendor/bin/phpunit

      # Run Laravel Dusk tests
      - run:
          name: Start xvfb
          background: true
          command: /usr/bin/Xvfb :0 -screen 0 1280x720x24

      - run:
          name: Open Browsers
          background: true
          command: DISPLAY=:0 ./vendor/laravel/dusk/bin/chromedriver-linux

      - run:
          name: Docker Host
          command: echo 127.0.0.1 my.site | sudo tee -a /etc/hosts

      - run:
          name: Serve Application
          command: sudo php artisan serve --host=my.site --port=8000
          background: true

      - run:
          name: Run Laravel Dusk tests
          command: php artisan dusk
0 likes
5 replies
brunofernandes's avatar

I fixed the problem by setting the APP_URL in the .env file to http://localhost:8000 and starting the server normally using php artisan serve

And make sure the database used by dusk isn't in-memory. I am using sqlite.

thewebdevelopers's avatar

I expect it would work using localhost, but as stated:

"Please note, I cannot simply use localhost as I have a subdomain/alias with routes and check domain within my routes/web.php"

mottihoresh's avatar

Did you ever found a solution for this issue? i am having a similar issue, where it's just rendering a blank white screen

1 like
thewebdevelopers's avatar

Unfortunately not, fine when running on localhost as above, but in terms of setting a specific hostname it would never seem to route correctly. For now I'm running Dusk tests locally prior to pull request, as needed to continue with my development, however I will revisit this one soon.

mottihoresh's avatar

I was able to get it to work at the end, seems like dusk was using the App_url envy variable whole must be a fully qualified domain. For example example.com wouldn’t work and http://example.com would.

Please or to participate in this conversation.