Docker Community Forums

Share and learn in the Docker community.

Got "Bad request" from dockerized Apache when requested by container name


this is my first post in the forum.
I have a php5.6 + apache application running in docker compose, named gru_joomla_1

Docker version: Docker version 19.03.8, build afacb8b7f0
Container image: joomla:3.9-php5.6-apache
Apache version in image: 2.4.25

If I try to make an http request from another container (from a different compose stack, with external network of gru_joomla_1 included to scope) to the one running apache (listening to port 80) i got a “400 Bad Request” error.
In order to make some test I installed curl in a couple of containers, trying to make the request, obtaining the same error:

curl http://gru_joomla_1/query/get_contatto.php?

<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
<p>Additionally, a 400 Bad Request
error was encountered while trying to use an ErrorDocument to handle the request.</p>
<address>Apache/2.4.25 (Debian) Server at Port 80</address>

I can successfully ping and make telnet connection to port 80 from the same container obtaining the error.

The strange thing is that I can succesfully browse the application from my browser and, moreover, curl works from the same container above if I use the internal docker ip address or any domain name (previously updating the /etc/hosts file of the container sendin the request)

Example of working tests:

For now I solved the problem by using an nginx image instead of apache, but why does apache answers with bad request if reached by container name?

Thank you in advance

Here’s my docker-compose.yml

version: '3.7'

    image: mysql:5.5.54
      - variables-gru.env
      - ./volumes/mysql-gru:/var/lib/mysql
      - ./init-gru:/docker-entrypoint-initdb.d
      - ./my.cnf:/etc/mysql/my.cnf
      - ./log/mysql-gru:/var/log
      - backend

    image: mysql:5.5.54
      - variables-joomla.env
      - ./volumes/mysql-joomla:/var/lib/mysql
      - ./init-joomla:/docker-entrypoint-initdb.d
      - ./my.cnf:/etc/mysql/my.cnf
      - ./log/mysql-joomla:/var/log
      - backend

    image: joomla:3.9-php5.6-apache
      - db-joomla
      - db-gru
      - variables-joomla.env
      - ./volumes/joomla-root:/var/www/gru
      - ./site.conf:/etc/apache2/sites-enabled/000-default.conf
      - ./log/joomla:/var/log
      - "80:80"
      - frontend
      - backend

    driver: bridge
    driver: bridge

Everything went fine, I just need to change that command to docker exec -it _mailman-web python createsuperuser in the readme.
Besides that you should not get a Error 400 at all, seems like a configuration error. You canc check some things:

Did you change example.orgin the example configs to your domain?
Make sure you’ve replaced with the correct path (I missed writing it in the block for port 80)
Make sure mailman-core and mailman-web did fully initialize the database and run their migrations (mailman-web needs some time to do that). Check with docker-compose logs -f mailman-web
Check if you’ve installed the needed apache2 modules and if you’ve enabled the site configuration with a2ensite lists.conf and reloaded apache config afterwards

Thank you for your help. I’ve just found the problem. It seems that Apache doesn’t like to receive requests through an hostname containing underscore characters.

Using the container_name directive in my docker-compose.yml (eg. gru-joomla) fixed the problem.

More info here:

I would suggest thinking about going one step further. See this article:

One change: if you want to be able to use Xdebug, change the proxy to another port (say 8090) rather than 9000.
Then, add this to the Dockerfile for the php container to move the php-fpm port away from the xdebug port:
RUN sed -i ‘s/9000/8090/’ /usr/local/etc/php-fpm.d/zz-docker.conf