If you want to do this programmatically (no manual text entry with gedit) here's a version for a Dockerfile based on user1341296's answer above:
FROM spittet/ruby-mysql
MAINTAINER [email protected]
RUN cp -R -p /var/lib/mysql /dev/shm && \
rm -rf /var/lib/mysql && \
sed -i -e 's,/var/lib/mysql,/dev/shm/mysql,g' /etc/mysql/my.cnf && \
/etc/init.d/mysql restart
Available on Docker hub here: https://hub.docker.com/r/richardjecooke/ruby-mysql-in-memory/