I have a dockercompose with MariaDB+PHPMyadmin. I’m running some commands inside db service but after them it ends with code 0 while i’m expecting a mariadb server running.
I checked my docker-compose.yml without commands and it worked fine.
This is my compose:
version: '3.1'
services:
db:
image: mariadb:10.3
command: |
sh -c " echo 'Starting Commands'&& apt-get update && apt-get install -y wget && wget https://downloads.mysql.com/docs/sakila-db.tar.gz && tar xzf sakila-db.tar.gz & & echo 'Extraction Finished' && mv sakila-db/sakila-schema.sql /docker-entrypoint-initdb.d/1.sql && mv sakila-db/sakila-data.sql /docker-entrypoint-initdb.d/2.sql && echo ' Finished Commands'"
environment:
MYSQL_ROOT_PASSWORD: notSecureChangeMe
phpmyadmin:
image: phpmyadmin
restart: always
ports:
- 8080:80
This is the output:
db_1 | Starting Commands
db_1 | Get:1
db_1 | Get:2
db_1 | Get:3
db_1 | Get:BLA BLA BLA
db_1 | Unpacking wget (1.20.3-1ubuntu1) ...
db_1 | Setting up wget (1.20.3-1ubuntu1) ...
db_1 | BLA BLA BLA
db_1 | Connecting to downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... connected.
db_1 | HTTP request sent, awaiting response... 200 OK
db_1 | Length: 732133 (715K) [application/x-gzip]
db_1 | Saving to: 'sakila-db.tar.gz'
db_1 | BLA BLA BLA
db_1 | 2021-11-10 23:28:49 (1.25 MB/s) - 'sakila-db.tar.gz' saved [732133/732133]
db_1 |
db_1 | Extraction Finished
db_1 | Finished Commands
root_db_1 exited with code 0
I supose thay "command" function could be overriding something but cannot find what.
2
Answers
If you look at the original Dockerfile for mariadb you will see that they have an ENTRYPOINT and CMD which start the database.
So try adding this to the list of command you run, like so (notice the last line in the command listing):
exec’ing into the container and checking existing databases:
This is the MariaDB definition in my
docker-compose.yaml
and I don’t have a problem with it.