1

I am new to docker and i have this docker .yml file (below) and i have a local set up of my WordPress site, i have imported a sql dump into a database in the 'container_web'. The problem i am having is that when i try to connect WordPress to the database inside the container i get this error "Error establishing a database connection." For the host i've used localhost, 127.0.0.1, mysql and none of them seems to work.

Do you know or could direct me in the right direction on what i should be checking in order to connect my WordPress install to the database?

services:
  web:
    build: .
    container_name: 'container_web'
    dns: '8.8.8.8'
    volumes:
      - ./:/var/www/html
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
    depends_on:
      - db
    ports:
      - 80:80
    restart: always
    environment:
      WORDPRESS_ENV: 'development'

  db:
    container_name: 'container_db'
    image: mysql:5.7
    ports:
      - 3306:3306
    volumes:
      - ./:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: mydatabase
      MYSQL_USER: user
      MYSQL_PASSWORD: password

volumes:
  mysql-data: {}
4
  • 1
    try to use the DB container_name as the host. Commented Jun 17, 2020 at 18:11
  • @abestrad just tried that but i still get the same error Commented Jun 17, 2020 at 18:18
  • Inspect the network, make sure you can see both. Additionally, test using the ip address, BTW from the anwser >>> Links are a legacy option. It's recommend to use networks instead. Commented Jun 17, 2020 at 18:31
  • What Database URL string you used in Wordpress? Commented Jun 17, 2020 at 20:01

0

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.