0

I am getting Error in Database connection frequently. It works fine for day or two but need to restart docker-compose manually every time it get this error.

can see anything significant when running docker-compose logs What am I doing wrong ? Here..

DockerFile

FROM wordpress

COPY wp-config.php /var/www/html/

RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf

EXPOSE 80

docker-compose version: '3.1'

services:

  wordpress_db:
    container_name: abcwordpressdb
    image: mariadb:latest
    restart: always
    volumes:
      - abcdb:/var/lib/mysql
    environment:
      MYSQL_USERNAME: root
      MYSQL_ROOT_PASSWORD: password
    ports:
      - "3306:3306"

  phpmyadmin:
    container_name: abcphpmyadmin
    image: phpmyadmin/phpmyadmin
    links:
        - wordpress_db:db
    ports:
        - "8181:80"
    environment:
      MYSQL_USERNAME: root
      MYSQL_ROOT_PASSWORD: password
      PMA_HOST: wordpress_db

  wordpress:
    build: ./wordpress
    container_name: abc_wordpress
    ports:
      - "80:80"
    volumes:
      - ./wp-content:/var/www/html/wp-content/
    restart: unless-stopped

volumes:
  abcdb:
1
  • This sounds like an issue with either disk space or memory of your mariadb container. Have you checked memory usage and disk space at the moment this error occured? Commented Nov 17, 2018 at 16:11

2 Answers 2

1

Database containers at times take longer to come up. So when your application container 'depends on' a database connection. It's nice to use the option

depends_on:
  - wordpress_db

This will make sure the database container comes up before the application

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

Comments

0

Found a solution here https://github.com/docker-library/mysql/issues/361

Just make sure to run backup before running this

# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql

# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE

Then

  1. docker-compose down
  2. Deleted old volumes (if there is no significant data) docker system prune --force --volumes
  3. Added command: --disable-partition-engine-check to mysql section in docker-compose.yml
  4. Ran it with docker-compose up -d to set it up in background.

Comments

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.