Why can I not transfer a db from one container to another?
In my case, I have 2 mariadb containers running with 2 seperate volumes:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
952988c62c2c mariadb:10.4 "docker-entrypoint.s…" 22 minutes ago Up 22 minutes 3306/tcp php_dev_db_1
799f2226367f mariadb:10.4 "docker-entrypoint.s…" 4 days ago Up 30 minutes (healthy) 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp test_magento-db-1
And I tried to transfer the database from one to another via a pipe:
docker exec 799f2226367f mysqldump -u magento -pmagento magento > docker exec 952988c62c2c mysql -u magento -pmagento magento
But I get the error:
mysqldump: Couldn't find table: "exec"
And I don’t know why.
I try to transfer the database from one to another via a pipe
so you need to use a pipe (|
) rather than a redirection (>
):
docker exec 799f2226367f mysqldump -u magento -pmagento magento | docker exec 952988c62c2c mysql -u magento -pmagento magento
The error you got happens because a redirection only consumes the following word, so your command is equivalent to
docker exec 799f2226367f mysqldump -u magento -pmagento magento exec 952988c62c2c mysql -u magento -pmagento magento > docker
i.e. mysqldump
tries to dump the magento
, exec
, 952988c62c2c
, and mysql
tables.