我有2个容器。其中之一是针对postgresql的。另一个用于php。
version: '3.7'
networks:
backend-network:
driver: bridge
frontend-network:
driver: bridge
services:
php-fpm:
container_name: k4fntr_php-fpm
build: ./docker/php-fpm
ports:
- "9000:9000"
volumes:
- ./:/var/www/k4fntr
depends_on:
- database
networks:
- backend-network
- frontend-network
database:
container_name: k4fntr_database
build: ./docker/postgres
restart: always
environment:
ENV: ${APP_ENV}
TESTING_DB: ${DB_DATABASE_TESTING}
POSTGRES_DB: ${DB_DATABASE}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
ports:
- "15432:5432"
volumes:
- ./docker/postgres/pg-data:/var/lib/postgresql/data:Z
networks:
- backend-network
我也有sh脚本,可以将生产数据库复制到本地。
#!/bin/bash
ssh -p 22000 -C -l user host 'sh /project/copy_prod.sh' > /tmp/backup.sql
(
echo "DROP DATABASE prod_copy;"
echo "CREATE DATABASE prod_copy OWNER k4fntr;"
) | (export PGPASSWORD=secret && psql -h 127.0.0.1 -U local)
export PGPASSWORD=secret && psql -h 127.0.0.1 -U local prod_copy < /tmp/backup.sql
但出现错误
bash:psql:找不到命令
是否可以从数据库容器中运行psql?