Skip to content

Wordpress container throwing "Connection refused" errors when using non-standard MySQL port #384

@mpmumau

Description

@mpmumau

I'm attempting to use a different port for my MySQL container in a docker-compose file I have set up to run with the Wordpress Docker image my docker-compose file looks like so:

version: '2'

services:
  db:
    image: mysql:latest
    volumes:
      - ./volumes/db:/var/lib/mysql
    restart: always
    ports:
      - "6951:3306"
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
  wordpress:
    depends_on:
      - db
    image: wordpress
    working_dir: /var/www/html
    volumes:
      - ./app:/var/www/html/wp-content
      - ./volumes/uploads:/var/www/html/wp-content/uploads
      - ./scripts:/opt/scripts
    ports:
      - "6952:80"
    restart: always
    links:
      - db:mysql
    environment:
      WORDPRESS_DB_HOST: db:6951
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      ENV: local
    build:
      context: ./
      dockerfile: docker/wordpress/Dockerfile
volumes:
    db_data:
    legacy_files:

However, after I bring the containers up with the above config, I am unable to access the Wordpress application via a browser, and likewise the docker logs command for the container results in the following error:

Warning: mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22

MySQL Connection Error: (2002) Connection refused

It seems as if there is some additional environment variable, perhaps, that I need to set in order to use a non-standard MySQL port. Any information about this would be much appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionUsability question, not directly related to an error with the image

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions