3

I am trying to work out how to create a Drupal dev environment using Docker. I am trying to use the Docker containers for Drupal (https://hub.docker.com/r/library/drupal/) and MySQL (https://hub.docker.com/r/library/mysql/) to set up a Drupal server.

I am assuming that I need to link the MySQL container to the Drupal container. I have created a docker-compose.yml file which seems to run fine on docker-compose up (I am using a Mac).

docker-compose.yml file:

drupal:
  image: drupal
  ports:
   - "8080:80"
  links:
   - db
db:
  image: mysql
  environment:
    MYSQL_ROOT_PASSWORD: mysql
    MYSQL_DATABASE: drupal
    MYSQL_USER: drupal
    MYSQL_PASSWORD: drupal
    MYSQL_ALLOW_EMPTY_PASSWORD: yes

After docker-composer completes, I can access the Drupal site from my web browser. The Drupal installation works up to the point where I have to enter the database details. At this point it fails:

enter image description here

6

Make sure to put in the "Host" of the MySQL database under "Advanced Configuration" as db and not the default localhost.

| improve this answer | |
2

When you link containers in docker compose, you still have to reference the database server in your configuration (in this case as 'db'); your database will be on db:3306.

Have a look at an example about doing it with Wordpress.

I suspect you are just not pointing it at the server.

You also set the database user as root, but in your yml that is drupal (which might be another issue).

| improve this answer | |
1

1. To get all container names and their ips in just one single command.

docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}' $(docker ps -aq)

Output:
/drupal7_drupal_1 - 172.17.0.3
/drupal7_db_1 - 172.17.0.2

2. Set up Database:
Database name: drupal
Database username: drupal
Database password: drupal
Host: 172.17.0.2

docker-compose.yml

drupal:
  image: drupal
  ports:
   - "8080:80"
  links:
   - db
db:
  image: mysql
  environment:
    MYSQL_ROOT_PASSWORD: drupal
    MYSQL_DATABASE: drupal
    MYSQL_PORT: 3306
    MYSQL_USER: drupal
    MYSQL_PASSWORD: drupal
| improve this answer | |
1

I've been working on a dev env for Drupal specifically using Docker and recently open sourced the BETA version with the intention to help others as well as streamline my dev setup : https://www.4alldigital.io/docker-drupal

Supposed to be a single command install and away you go. would love feedback if it helps or hinders... and how it can better server Drupal devs who wanna spend less time on local devOps

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.