Apache conf could not resolve host

apache

#1

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
</VirtualHost>

And this is my config.yml:

version: 2

jobs:
  build:
    branches:
      only:
        - master
    docker:
      - image: circleci/php:7.1-apache-jessie-node-browsers

    working_directory: ~/circleci-resolve-host

    steps:
      - 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?
#2

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

I’d expect to have to do echo '127.0.0.1 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.


#3

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?


#4

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

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

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


#5

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.


#6

@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/


#7

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


#8

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