I am trying to get my app working with docker but I am having trouble getting my database to display. It seems my laravel application itself can access it but I need to access it myself in order to troubleshoot issues.
The problem when I try to access localhost:4306 (the port of which the db is on). when I go to that in the browser it outputs:
J��� 5.7.22� ���X5g ^A�яя�яБ����������8O?x tdm�mysql_native_password���я„Got packets out of order
The db section of the .env is:
DB_CONNECTION=mysql DB_HOST=mysql DB_PORT=3306 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret
the docker-compose is:
version: '3.2' networks: laravel: services: nginx: image: nginx:stable-alpine container_name: nginx ports: - "8088:80" volumes: - ./src:/var/www/html - ./nginx/default.conf:/etc/nginx/conf.d/default.conf depends_on: - php - mysql networks: - laravel mysql: image: mysql:5.7.22 container_name: mysql restart: unless-stopped tty: true ports: - "4306:3306" volumes: - ./mysql:/var/lib/mysql environment: MYSQL_DATABASE: homestead MYSQL_USER: homestead MYSQL_PASSWORD: secret MYSQL_ROOT_PASSWORD: secret SERVICE_TAGS: dev SERVICE_NAME: mysql networks: - laravel php: build: context: . dockerfile: Dockerfile container_name: php volumes: - ./src:/var/www/html ports: - "9000:9000" networks: - laravel
and the Dockerfile referenced in the docker-compose.yml is:
FROM php:7.4-fpm-alpine # Setup GD extension RUN apk add --no-cache freetype libjpeg-turbo libpng freetype-dev libjpeg-turbo-dev libpng-dev && docker-php-ext-configure gd --with-freetype=/usr/include/ # --with-png=/usr/include/ # No longer necessary as of 7.4; https://github.com/docker-library/php/pull/910#issuecomment-559383597 --with-jpeg=/usr/include/ && docker-php-ext-install -j$(nproc) gd && docker-php-ext-enable gd && apk del --no-cache freetype-dev libjpeg-turbo-dev libpng-dev && rm -rf /tmp/* RUN docker-php-ext-install pdo pdo_mysql RUN chown -R 1000:www-data /var/www/html
Advertisement
Answer
You are trying to connect to database through HTTP protocol, that’s why you are receiving that message.
You can connect to MySql database using phpMyAdmin (web client) or any installed MySql client.
Docker has phpMyAdmin available: https://hub.docker.com/r/phpmyadmin/phpmyadmin/
There are many MySql Clients available. Just search in your favorite search engine by “mysql client” followed by the name of your Operating System.