我正试图让我的应用程序与docker一起工作,但我在显示数据库时遇到了问题。我的laravel应用程序本身似乎可以访问它,但为了解决问题,我需要自己访问它。
尝试访问localhost:4306(数据库所在的端口(时出现的问题。当我在浏览器中转到它时,它会输出:
J���
5.7.22�
���X5g ^A�яя�яБ����������8O?x
tdm�mysql_native_password���я„Got packets out of order
env的数据库部分是:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
码头工人的组成是:
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
docker-compose.yml中引用的Dockerfile为:
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
您正试图通过HTTP协议连接到数据库,这就是您收到该消息的原因。
您可以使用phpMyAdmin(web客户端(或任何已安装的MySql客户端连接到MySql数据库。
-
Docker有phpMyAdmin可用:https://hub.docker.com/r/phpmyadmin/phpmyadmin/
-
有许多MySql客户端可用。只需在您喜爱的搜索引擎中搜索";mysql客户端";然后是操作系统的名称。