R
R
Ruslan Absalyamov2019-10-27 19:37:12
Yii
Ruslan Absalyamov, 2019-10-27 19:37:12

How to run yii2 migration in docker?

Configuration

version: '3'

services:
  webserver:
    container_name: apache-php_kfnp_yii2
    build:
      context: .
      dockerfile: ./docker/Dockerfile
    environment:
      XDEBUG_CONFIG: remote_host=host.docker.internal
      PHP_IDE_CONFIG: serverName=localhost
    ports:
    - 80:80
    volumes:
    - ./:/var/www
    links:
    - db
    depends_on:
    - db

  db:
    container_name: mysql_kfnp_yii2
    image: percona:latest
    command: --default-authentication-plugin=mysql_native_password
    restart: on-failure
    ports:
    - 3306:3306
    expose:
      - 3306
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: yii2basic
      MYSQL_USER: mysqluser
      MYSQL_PASSWORD: mysqluser

But I try to run the docker to implement the migration docker-compose exec apache-php_kfnp_yii2 php yii
But it says No such service: apache-php_kfnp_yii2
Although the container is running
And I can enter it docker exec -it apache-php_kfnp_yii2 bash
I didn’t quite understand how to run the migration in the project
If I run the migration inside the container, I get an error
Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [2002] No such file or directory'

in /Users/user/Sites/app/vendor/yiisoft/yii2/db/Connection.php:632

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Rybalka, 2019-10-27
@rusline18

docker exec -it apache-php_kfnp_yii2 bash -c "cd /var/www && php yii mgrate"

G
grinat, 2019-10-28
@grinat

Specify working_dir to the webserver: /var/www

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question