I am trying to run a mysql benchmark (sysbench) inside my docker container. The script works well and performs the benchmark while running in the host terminal but when I try to run it inside a container I get an error as:
FATAL: unable to connect to MySQL server, aborting... FATAL: error 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) ALERT: Error: failed to determine table 'sbtest' type! ALERT: MySQL error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) FATAL: failed to get database capabilities!
My docker file is:
FROM ubuntu:14.04
RUN apt-get -y update && apt-get install -y sysbench
ADD ./script.sh /code/script.sh
WORKDIR /code
ENTRYPOINT ./script.sh
And my script is:
export DEBIAN_FRONTEND="noninteractive"
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
sudo apt-get -y install mysql-server
sudo mysql --user="root" --password="root" -e "create database dbtest"
sudo sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=dbtest --mysql-user=root --mysql-password=root prepare
sudo sysbench --test=oltp --oltp-table-size=1000000 --oltp-test-mode=complex --oltp-read-only=off --num-threads=6 --max-time=60 --max-requests=0 --mysql-db=dbtest --mysql-user=root --mysql-password=root run
How can I fix this, because the same script works on a normal Linux machine?