MySQL Setup using Docker

I’m trying to create a setup where when I do a “docker run” off a Dockerfile that I’ve created, docker will install and setup mysql, and then create a database for me to use.

Below is my simple docker file that pulls from the existing dockerfile/mysql

  • Is there a best practice on setting up glibc on docker alpine linux base image?
  • How to change the Docker image installation directory on Mac?
  • how to dump data to the database at startup
  • How to figure out, what slows down docker?
  • Building a docker container: will it be public?
  • Build container found dead before completing the build. Build container died because it was out of memory, or the Docker image was missing glibc
  • FROM dockerfile/mysql
    COPY dbsetup.sql /tmp/dbsetup.sql
    RUN bash -c "/usr/bin/mysqld_safe &" && \
      sleep 5 && \
      mysql -u root -e "CREATE DATABASE mydb"
    

    It seems to run, but when I connect to the DB (using the IP I received from the boot2docker ip command), the database doesnt’ exist.

    Anyone have any ideas?

    Note: I had originally tried to run all three of those commands in separate RUN statements, but that didn’t work. Explanation of why here.

  • Fixing World-writable MySql error in Docker
  • How to edit source code of a python project deployed in docker
  • Kubernetes executor on Gitlab ERROR: Job failed: image pull failed
  • Docker. npm install -> Error: getaddrinfo ENOTFOUND
  • How to solve “shell request failed on channel 0” on RHEL container?
  • What are the minimum requirements of neo4j?
  • 2 Solutions collect form web for “MySQL Setup using Docker”

    You should take example on the dockerfile/mysql Dockerfile which has the following RUN statement:

    RUN echo "mysqld_safe &" > /tmp/config \
        && echo "mysqladmin --silent --wait=30 ping || exit 1" >> /tmp/config \
        && echo "mysql -e 'GRANT ALL PRIVILEGES ON *.* TO \"root\"@\"%\" WITH GRANT OPTION;'" >> /tmp/config \
        && bash /tmp/config \
        && rm -f /tmp/config
    

    In your case you would put in your Dockerfile:

    RUN echo "mysqld_safe &" > /tmp/config \
        && echo "mysqladmin --silent --wait=30 ping || exit 1" >> /tmp/config \
        && echo "mysql -u root -e \"CREATE DATABASE mydb\"" >> /tmp/config \
        && bash /tmp/config \
        && rm -f /tmp/config
    

    I would advise either using the standard mysql container image or borrow from its dockerfile

    It uses environment variables to control the database name and admin credentials.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.