1

I have 3 Docker containers(nginx, php and mysql) bundled together via docker-compose.

In /etc/nginx/sites-enabled I have .conf files for 2 websites.

magento2.loc  > magento2.conf
pma.loc       > pma.conf

On the host(Ubuntu) I modified /etc/hosts accordingly.

127.0.0.1  > magent2.loc
127.0.0.1  > pma.loc

docker-compose.yml

version: '2'

services:
    nginx:
        (...)
        links:
            - php
        (...)
    php:
       (...)

After running docker-compose up, server log in console shows:

  • response from php and nginx for magento2.loc < correct
  • but only response from nginx(no php) from pma.loc < incorrect

How do I make pma.loc work with PHP? Do I need multiple PHP containers for that?

3
  • I've made a habit of creating separate containers for each web site. Then you have to make sure your configs are correct in order to be able to deliver both (or more) websites. Commented Mar 2, 2018 at 14:19
  • @JayBlanchard do you mean separate php containers or all? I need a single mysql container that can be accessed by phpMyAdmin and an app. Would it work with 2 x php, 2 x nginx, 1 x shared mysql? Commented Mar 2, 2018 at 14:23
  • phpMyAdmin is an app, not a database. I put the database(MySQL) in a container and then link my web containers to the MySQL container. Commented Mar 2, 2018 at 14:25

1 Answer 1

1

The easiest way to achieve what you're trying to achieve is to first, place your database in its own container. Then, for each website create a container having the necessary components to run the website as shown below:

Websites w/ Shared Database

You would establish a link between each website container and the database container. You will have to then, of course, create virtual hosts for each website so they do not have port conflicts.

There is a slightly more complex solution to the problem in which you use yet another Docker container to act as a proxy which directs traffic appropriately to each web site. The other solution, which is what you're trying to do now, is run multiple websites in the same container in which you have to establish server blocks (Nginx's term for virtual hosts) for each website in the container.

In any case you should place your database in its own container and link to that container in the Docker run command or Docker-Compose setup.

Sign up to request clarification or add additional context in comments.

2 Comments

Many thanks Jay. The image is what I had in mind after reading your comment but I wasn't sure if it'll work. Then, I found 'corbinu/docker-phpmyadmin' image, linked it with my database container which in turn was already linked to nginx and php containers. I was reading about the proxy solution but haven't tried it yet. The 'server blocks' solution unfortunately didn't work - request was reaching nginx container but did not go through the php container.
Glad to have helped Alan. The proxy solution works well (I have a couple of instances of it running in production where I needed to conserve hardware and maximize database usage.) but can be finicky to setup. Gimme' a shout if you even want to try it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.