学说和码头工人的问题



我在使用 Doctrine 创建数据库时遇到问题 ( migration:migrate )。我收到此错误:

不知道这样的主机

使用localhost:3306而不是 db 时问题得到解决,但是在使用 REST 服务发送请求时遇到了问题。

总结:使用 localhost:3306 - migration:migrate 有效,而 REST 服务

不起作用,使用 db - migration.migrate 不起作用,REST 服务有效。这些是我的设置:

.env

    ###> doctrine/doctrine-bundle ###
    # Format described at http://docs.doctrine-project.org/projects/doctrine- 
    dbal/en/latest/reference/configuration.html#connecting-using-a-url
    # For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
    # Configure your db driver and server_version in 
    config/packages/doctrine.yaml
    DATABASE_URL=mysql://user:pass@db/db_name
    ###< doctrine/doctrine-bundle ###

docker-compose.yml

version: "2"
services:
  db:
    image: mysql:5.7
    container_name: db_container
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=123
      - MYSQL_DATABASE=db_name
      - MYSQL_USER=user
      - MYSQL_PASSWORD=pass
    volumes:
      - ./mysql/data:/var/lib/mysql:rw
    ports:
      - 3306:3306
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin_container
    links:
      - db:db
    ports:
      - 8081:80
  webserver:
    image: nginx:alpine
    container_name: symfony-webserver
    volumes:
      - ./symfony:/var/www/html
      - ./docker/nginx/site.conf:/etc/nginx/conf.d/default.conf
    ports:
      - 8082:80
    depends_on:
      - php-fpm
  php-fpm:
    build: docker/php-fpm
    container_name: symfony-php-fpm
    volumes:
      - ./symfony:/var/www/html
      - ./docker/php-fpm/php-ini-overrides.ini:/etc/php/7.0/fpm/conf.d/99-overrides.ini
    links:
      - db

学说.yaml

parameters:
    # Adds a fallback DATABASE_URL if the env var is not set.
    # This allows you to run cache:warmup even if your
    # environment variables are not available yet.
    # You should not need to change this value.
    env(DATABASE_URL): ''
doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci
        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'AppEntity'
                alias: App

所有命令都应在容器内运行。

要进入您的 FPM 容器,您可以运行docker-compose exec -it php-fpm bash(或ash,具体取决于您使用 Debian 基础映像还是 Alpine)

->在此 shell 中,您可以执行 bin/console 原则:迁移命令

最新更新