title: MySQL Master Slave configuration using Docker-compose
body: <p>Okay so I wanted to make a master slave replication for mysql for my website hosted in nginx run by php. I've managed to connect to the master mysql however, there seems to have some error on my slave container. I was wondering if there is anything wrong or what I should add in order to solve this issue.</p>
  <pre><code>You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD
  2020-10-15 09:09:44+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.6+maria~focal started.
  2020-10-15 09:09:45+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
  2020-10-15 09:09:45+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.6+maria~focal started.
  2020-10-15 09:09:45+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
  You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD
  </code></pre>
  <p>My docker-compose.yml file</p>
  <pre><code>version: &quot;3.3&quot;
    
  services:
  
    mysql:
  
      image: mariadb:latest
      restart: always
      ports:
        - &quot;3306&quot;
      environment:
        MYSQL_REPLICATION_MODE: master
        MYSQL_REPLICATION_USER: repl_user
        MYSQL_REPLICATION_PASSWORD: repl_password
        MYSQL_ROOT_PASSWORD: rootpw
        MYSQL_DATABASE: database
        MYSQL_USER: user
        MYSQL_PASSWORD: mypw
      networks:
        - my-net
  
    mysql-slave:
        image: mariadb:latest
        restart: always
        ports:
          - &quot;3306&quot;
        depends_on:
          - mysql
        environment:
           MYSQL_REPLICATION_MODE: slave
           MYSQL_REPLICATION_USER: repl_user
           MYSQL_REPLICATION_PASSWORD: repl_password
           MYSQL_MASTER_HOST: mysql
           MYSQL_MASTER_PORT_NUMBER: 3306
           MYSQL_MASTER_ROOT_PASSWORD: rootpw
           MYSQL_ROOT_PASSWORD: rootpw
        networks:
          - my-net
    myphp:
      build: ./src/php
      restart: always
      expose:
        - &quot;9000&quot;
      volumes:
        - ./src:/var/www/html
      depends_on:
        - mysql
        - mysql-slave
      networks:
        - my-net
  
    mynginx:
  image: nginx
  restart: always
  volumes:
    - ./src/nginx.ini:/etc/nginx/conf.d/default.conf
    - ./src/php-fpm.conf:/etc/php/7.4/fpm/php-fpm.conf
    - ./src/www.conf:/etc/php/7.4/fpm/pool.d/www.conf
    - ./src:/var/www/html/
  ports:
    - &quot;8080:80&quot;
  depends_on:
    - myphp
  networks:
    - my-net
  </code></pre>
  <p>networks:
  my-net:
  driver: bridge</p>