Apache conf could not resolve host



So from one day to the next my Behat tests suddenly started failing as curl couldn’t resolve my custom host anymore. I’ve set up a very basic repo containing just an Apache conf and the config.yml to demonstrate that. In the end I simply $ curl example.localhost but it always returns cURL error 6: Could not resolve host: example.localhost. Whereas $ curl localhost just works fine.

This is my example.conf:

<VirtualHost *:80>
  DocumentRoot /home/circleci/circleci-resolve-host
  ServerName example.localhost

And this is my config.yml:

version: 2

        - master
      - image: circleci/php:7.1-apache-jessie-node-browsers

    working_directory: ~/circleci-resolve-host

      - checkout

      - run:
          name: Install some basic tools
          command: |
            sudo apt-get update -y
            sudo apt-get upgrade -y
            sudo apt-get install -y nano

      - run:
          name: Configure & start Apache
          command: |
            sudo cp ~/circleci-resolve-host/.circleci/example.conf /etc/apache2/sites-available/example.conf
            sudo a2ensite example
            sudo service apache2 start
      - run:
          name: Run tests
          command: |
            curl example.localhost

Is this a bug? Or what am I missing?

What's the docker hostname for the second container?

Have you added example.localhost into your /etc/hosts?

I’d expect to have to do echo ' example.localhost' >> /etc/hosts in an earlier step. I appreciate this worked before, but I am not sure why - example.localhost is not a default domain on Ubuntu as far as I know.


Someone here found their DNS resolution changed around 2nd Feb. I don’t know if that’s related, when did your own DNS issues start?


Thanks @halfer! Yes that was exactly around the time when it started. Updating /etc/hosts fixed it.

  - run:
      name: Update host file
      command: |
        echo example.localhost | sudo tee -a /etc/hosts
        cat /etc/hosts

That means that maybe *.dev was somehow resolved automatically before.


Great! Don’t forget to click on the ‘solved’ device on your above answer, so that it marks it for future readers.

Out of interest, what does the tee -a do - is that another way of appending to the hosts file? I’m familiar with using it to split stdout to both stdout and file, but I’ve not seen that construction before.


@halfer$ echo and $ sudo echo didn’t work. But as part of a pipe tee can take the input, elevate permissions and write to the file. -a stands for --append the output to a file.

Super nice source: https://shapeshed.com/unix-tee/


Great, I just learned something! :smiley_cat: Thanks for the link.


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.