skip to Main Content

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


  1. If you look at the original Dockerfile for mariadb you will see that they have an ENTRYPOINT and CMD which start the database.

    ENTRYPOINT ["docker-entrypoint.sh"]
    CMD ["mysqld"]
    

    So try adding this to the list of command you run, like so (notice the last line in the command listing):

      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' && 
                 docker-entrypoint.sh mysqld"
        environment:
          MYSQL_ROOT_PASSWORD: notSecureChangeMe
    

    exec’ing into the container and checking existing databases:

    root@c875454e15cb:/# mysql -u root -pnotSecureChangeMe -e "show databases"
    
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sakila             | <<<<<<<<<<<<<<<<<<<
    +--------------------+
    
    Login or Signup to reply.
  2. This is the MariaDB definition in my docker-compose.yaml and I don’t have a problem with it.

    services:
      mariadb:
        image: mariadb:10.6-focal
        restart: always
        ports:
          - 3306:3306
        environment:
          MYSQL_ROOT_PASSWORD: <password>
          MYSQL_DATABASE: <database>
        volumes:
          - mariadb-data:/var/lib/mysql
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search