Running MariaDB in a docker container using docker stack

I’m trying to follow the instructions on https://docs.docker.com/get-started/part3/ but changing it to a single node MariaDB database. I am using a docker-compose.yml file that looks like this…

version: "3"
services:
  database:
    image: mariadb:latest
    environment:
      MYSQL_DATABASE: jeesample
      MYSQL_USER: jeeuser
      MYSQL_PASSWORD: password
    networks:
    - webnet
    ports:
    - "3307:3306"
networks: 
  webnet:

Then I start it using

  • docker mysql connection via php
  • Windows Docker in Linux machine
  • how force deleting docker image affects existing containers using it
  • Timeout issue on while running docker run for onlyoffice document server integration
  • Run script from host machine on Docker container with exec [closed]
  • How to connect to docker container from browser on host?
  • docker stack deploy -c docker-compose.yml jeesample
    

    However, when I look at docker stack ps jeesample I get the following:

    ID            NAME                      IMAGE           NODE  DESIRED STATE  CURRENT STATE                   ERROR                      PORTS
    9yjyzmi86aqm  jeesample_database.1      mariadb:latest  moby  Running        Running less than a second ago
    gqamjzc2u1fw   \_ jeesample_database.1  mariadb:latest  moby  Shutdown       Failed 6 seconds ago            "task: non-zero exit (1)"
    615zc8s0rts1   \_ jeesample_database.1  mariadb:latest  moby  Shutdown       Failed 18 seconds ago           "task: non-zero exit (1)"
    pod5ldwn6p6v   \_ jeesample_database.1  mariadb:latest  moby  Shutdown       Failed 27 seconds ago           "task: non-zero exit (1)"
    ma1gkri9os14   \_ jeesample_database.1  mariadb:latest  moby  Shutdown       Failed 37 seconds ago           "task: non-zero exit (1)"
    

    Trying to connect to it using jdbc:mariadb://localhost:3307/jeesample from a SQL client on my local machine fails because I am unable to connect

  • VirtualBox and Nginx very slowly serving cached static JS and CSS files
  • I am not able to configure Docker VM for Lightbend ConductR. Sandbox init is throwing FileNotFoundError
  • Deny docker container to write host's filesystem
  • How to use nested docker.image('test_image').inside() in a Jenkins pipeline
  • ssh key generation using dockerfile
  • Securing local docker private registry
  • One Solution collect form web for “Running MariaDB in a docker container using docker stack”

    One way of diagnosing this issue is to look at the logs. To get the logs do docker ps to get a list of the containers then docker logs -f <container ID> to get the log result. Since it is on a docker-compose the container may go away after a short while so the -f option will keep it connected until it terminates.

    To resolve the issue which the logs say that there needs to be a password for the root user, I just needed to add

    MYSQL_RANDOM_ROOT_PASSWORD: "true"
    

    Although there are other options such has

    MYSQL_ROOT_PASSWORD: "blah" // visible on source
    MYSQL_ALLOW_EMPTY_PASSWORD: "yes" // not recommended
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.