Search code examples
mysqllinuxdockerfig

Docker - MySQL container does not keep running


I need some help with using MySQL in a Docker container. I thought the entire point of Docker was to isolate processes in sandboxes and have them run like normal processes - I am not getting this functionality.

Whenever I run a MySQL container that I have built from my own image, it runs for 2 seconds, then stops. Trying docker run -i -t <imageid> gives me this:

root@CenturionX:/home/centurionx/Code/Git/gdms-rcon# docker run -i -t e2d
150221 05:25:21 mysqld_safe Logging to '/var/lib/mysql/28123b6d1dad.err'.
150221 05:25:21 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
150221 05:25:21 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
root@CenturionX:/home/centurionx/Code/Git/gdms-rcon# 

Why does the daemon not stay open? I have my Dockerfile, which looks like:

# This docker file constructs a MySQL database instance
FROM mysql:latest

ADD . /gdms-rcon/mysql
WORKDIR /gdms-rcon/mysql

ENTRYPOINT ["/usr/bin/mysqld_safe"]

EXPOSE 3306

And a fig.yml file to help me automate the build process:

mysql:
  build: .
  volumes:
    - .:/gdms-rcon/mysql
  working_dir: /gdms-rcon/mysql
  ports:
    - "3306:3306"
  environment:
    - MYSQL_DATABASE=mydb
    - MYSQL_ROOT_PASSWORD=mypassword

Solution

  • mysql official image have a /entrypoint.sh script that is needed to run when you start the image in order to configure and running the container correctly. It seems that running /usr/bin/mysqld_safe instead doesn't configure correctly mysql and the process mysqld_safe ends, so the container also ends.

    Try replacing your ENTRYPOINT:

    # This docker file constructs a MySQL database instance
    FROM mysql:latest
    
    ADD . /gdms-rcon/mysql
    WORKDIR /gdms-rcon/mysql
    
    ENTRYPOINT ["/entrypoint.sh"]
    
    EXPOSE 3306