在 Docker PHP 容器内使用 mysqldump 命令

问题描述 投票:0回答:1

我是 Docker 新手,现在我想使用

spateie/laravel-backup
包来备份我的项目和数据库。

我需要在 Php 容器内运行

mysqldump
命令

当我在DB容器中运行

mysqldump
命令时,我可以正常使用它,但我在Php容器中找不到这个命令。

这是我的

docker-compose.yml

version: '2'

services:
  project-db:
    image: mariadb:10.3.35
    container_name: project-db
    volumes:
      - ./.configs/mysql_data:/var/lib/mysql
    ports:
      - "3309:3306"
    env_file:
      - ./.configs/.env.setup

  project-nginx:
    image: nginx:stable
    container_name: project-nginx
    volumes:
      - ./workspace/project/:/var/www/project/
      - ./.configs/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
    ports:
      - "80:80"
    links:
      - project-php

  project-php:
    build: .
    container_name: project-php
    volumes:
      - ./workspace/project/:/var/www/project/
      - ./.configs/php/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini
    links:
      - project-db
mysql docker containers laravel-backup
1个回答
0
投票

您正在

build: .
服务中使用
project-php

我猜你有

Dockerfile
,尝试添加:

RUN apt-get update \
    && apt-get install -y default-mysql-client

如果您使用基于

alpine
的图像,请添加:

RUN apk add --no-cache mariadb-client

这应该在您的 PHP 容器上安装

mysqldump


还可以在服务旁边的

networks
中使用
docker-compose.yml
。这样,您的容器将位于同一网络上,并且能够相互“通信”。

version: '2'

services:
  project-db:
    image: mariadb:10.3.35
    container_name: project-db
    volumes:
      - ./.configs/mysql_data:/var/lib/mysql
    ports:
      - "3309:3306"
    env_file:
      - ./.configs/.env.setup
    networks:
      - ani-metwork-name

  project-nginx:
    image: nginx:stable
    container_name: project-nginx
    volumes:
      - ./workspace/project/:/var/www/project/
      - ./.configs/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
    ports:
      - "80:80"
    links:
      - project-php
    networks:
      - ani-metwork-name

  project-php:
    build: .
    container_name: project-php
    volumes:
      - ./workspace/project/:/var/www/project/
      - ./.configs/php/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini
    links:
      - project-db
    networks:
      - ani-metwork-name

networks:
    ani-metwork-name:
        driver: bridge
© www.soinside.com 2019 - 2024. All rights reserved.