Docker + MySQL: returned a non-zero code: 2

I'm trying to build a Dockerfile for MySQL, but for some reason I keep receiving this error code 2. I can build it manually on an identical server, so I am out of good ideas what is going wrong, and hope someone here can help me sort it out?

Also I would like to hear feedback on my entrypoint approach (tail -f /dev/stdout)

ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Copenhagen

RUN apt-get update && apt-get -yq upgrade \
    && apt-get install -yq mysql-server \
    && mysql_secure_installation --use-default --password=123456 \
    && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
    && ln -sf /dev/stdout /var/log/mysqld.err \
    && { \
        echo "[mysqld]"; \
        echo "bind-address=0.0.0.0"; \
    } > /etc/mysql/conf.d/bind_0.0.0.0.cnf \
    && { \
        echo "#!/usr/bin/env bash"; \
        echo "set -e"; \
        echo "rm -f /run/mysqld/mysqld.pid"; \
        echo "/usr/bin/mysqld_safe"; \
        echo "tail -f /dev/stdout"; \
    } > /usr/local/bin/entrypoint \
    && chmod a+rx /usr/local/bin/entrypoint \
    && apt-get -yq clean autoclean && apt-get -yq autoremove \
    && rm -rf /var/lib/apt/lists/*

EXPOSE 3306/tcp

ENTRYPOINT ["entrypoint"]

Comments (12)

j's photo

port overlap on the host machine?

Show +9 replies
Emil Moe's photo

Software Engineer & Consultant

I succeeds if I remove the whole password part, so at least I have isolated the issue

Emil Moe's photo

Software Engineer & Consultant

j

I solved out the mystery, I need to run all these commands after the container is created. So during creation I store the init script in a file, when "booting" I check that the init script exists, if it does i run it and delete, so next time it won't be run.