如何将YII2迁移导出到Docker容器中

发布于 2025-02-10 16:54:34 字数 1191 浏览 3 评论 0原文

我已经成功地使用了Docker的基本YII2应用程序来实现我的基本YII2应用程序,并在localhost:8000上运行。但是,我无法有效地使用该应用程序,因为其大多数数据都存储在迁移文件中。有没有办法在运行后将迁移导出到Docker中? (或执行期间)

这是我的Docker撰写文件

version: '2'
services:
  php:
    image: yiisoftware/yii2-php:7.1-apache
    volumes:
      - ~/.composer-docker/cache:/root/.composer/cache:delegated
      - ./:/app:delegated
    ports:
      - '8000:80'
    networks:
      - my-network
  db:
    image: mysql:5.7
    restart: always
    environment:
      - MYSQL_DATABASE=my-db
      - MYSQL_PASSWORD=password
      - MYSQL_ROOT_PASSWORD=password
    ports:
      - '3306:3306'
    expose:
      - '3306'
    volumes:
      - mydb:/var/lib/mysql
    networks:
     - my-network
  memcached:
    container_name: memcached
    image: memcached:latest
    ports:
        - "0.0.0.0:11211:11211"
volumes:
  restatdb:
networks:
  my-network:
    driver: bridge

和我的Dockerfile

FROM alpine:3.4

ADD . /

COPY ./config/web.php ./config/web.php

COPY . /var/www/html

# Let docker create a volume for the session dir.
# This keeps the session files even if the container is rebuilt.
VOLUME /var/www/html/var/sessions

I have successfully containerized my basic Yii2 application with docker and it runs on localhost:8000. However, I cannot use the app effectively as most of its data are stored in migration files. Is there a way I could export the migrations into docker after running it? (or during execution)

This is my docker compose file

version: '2'
services:
  php:
    image: yiisoftware/yii2-php:7.1-apache
    volumes:
      - ~/.composer-docker/cache:/root/.composer/cache:delegated
      - ./:/app:delegated
    ports:
      - '8000:80'
    networks:
      - my-network
  db:
    image: mysql:5.7
    restart: always
    environment:
      - MYSQL_DATABASE=my-db
      - MYSQL_PASSWORD=password
      - MYSQL_ROOT_PASSWORD=password
    ports:
      - '3306:3306'
    expose:
      - '3306'
    volumes:
      - mydb:/var/lib/mysql
    networks:
     - my-network
  memcached:
    container_name: memcached
    image: memcached:latest
    ports:
        - "0.0.0.0:11211:11211"
volumes:
  restatdb:
networks:
  my-network:
    driver: bridge

and my Dockerfile

FROM alpine:3.4

ADD . /

COPY ./config/web.php ./config/web.php

COPY . /var/www/html

# Let docker create a volume for the session dir.
# This keeps the session files even if the container is rebuilt.
VOLUME /var/www/html/var/sessions

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久而酒知 2025-02-17 16:54:35

可以在Docker中运行YII命令。首先,让YII2容器在背景或端子的另一个选项卡中运行。 YII命令可以使用交互式接口上的docker exec运行,这将使我们与运行容器

sudo docker exec -i< container -iD> php yii迁移/UP

获得容器ID

您可以使用sudo docker ps

It is possible to run yii commands in docker. First let the yii2 container run in the background or another tab of the terminal. The yii commands can be run using the docker exec on the interactive interface which would let us interact with the running container

sudo docker exec -i <container-ID> php yii migrate/up

You can get the container ID using

sudo docker ps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文