1

So this is my Dockerfile:

FROM alpine

RUN apk add --update --upgrade --no-cache mysql mysql-client

RUN rm -rf /etc/my.cnf /etc/mysql/* /etc/mysql.d/ && \
mkdir -p /var/lib/mysql /var/run/mysqld && \
chown -R mysql /var/lib/mysql /run/mysqld && \
chgrp -R mysql /var/lib/mysql /run/mysqld && \
mysql_install_db --user=mysql --ldata=/var

EXPOSE 3306

USER mysql

CMD ["sh", "mysqld_safe --data=/var"]

My issue is that when I run the container with the image it does not find mysqld_safe. But when I run the command manually like this: docker run mysql mysqld_safe --data=/var it works ! I try to change the dockerfile with: CMD ["sh", "cat -"] to see if the problem is with the mysqld_safe command but same issue here, it does not find cat except when I run it with docker run mysql cat -.

Is the problem come from busybox on alpine, or from PATH ? I have no idea for now and I require you help.

nail0x
  • 43
  • 4

1 Answers1

0

You're missing the -c flag to sh that tells it to parse/run the next argument to the shell. Without that, I believe it's looking for a script with the name mysqld_safe --data=/var to run, that's not the script mysqld_safe with the arg --data=/var, but a single script name with a space, dashes, and equals sign in the directory name. Instead you want:

CMD ["sh", "-c", "mysqld_safe --data=/var"]
BMitch
  • 5,189
  • 1
  • 21
  • 30