I am trying to output the progress of an import of an .sql
file inside a mariadb docker container.
I have the following file/directory setup:
│- docker-compose.yml
│- Dockerfile
│- import.sh
└── sql
- test.sql (rather big: ~ 1GB)
My docker-compose.yml
is as simple as...
services:
db:
build: ./
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
- ./:/docker-entrypoint-initdb.d
...with the following Dockerfile to install pv
(pipe viewer). pv
should give me a progress bar how far the import is currently...
FROM mariadb
RUN apt-get update && apt-get install -y pv
The import.sh
will be executed through the mapped volume in /docker-entrypoint-initdb.d
as described here.
#!/bin/bash
# create db
mysql -uroot -proot <<-EOF
CREATE DATABASE test;
EOF
# import sql file and output progress with pv
echo "importing test.sql..."
pv --force "/docker-entrypoint-initdb.d/sql/test.sql" | mysql -uroot -proot "test"
Now, if I run docker-compose up
it only outputs the 100%
pv output at the end of the import:
importing test.sql...
953MiB 0:01:24 [11.2MiB/s] [================================>] 100% 0:05:42
If I execute the same command inside the container it works and it gives me a moving progress bar:
pv --force "/docker-entrypoint-initdb.d/sql/test.sql" | mysql -uroot -proot "test"
60.4MiB 0:00:14 [5.79MiB/s] [=> ] 6% 0:04:53
How can I get this progress bar on docker-compose up
instead of the loong wait and the 100%
output?