Install Mysql on a docker container

I am trying to run mysql in a modified ubuntu image that includes installing Node.js and a basic mysql installation using below docker file

# Memcached # use the ubuntu base image provided by dotCloud FROM ubuntu/mysqlbase MAINTAINER Hitesh # make sure the package repository is up to dat//e #RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list #RUN apt-get update #RUN apt-get install -y mysql-client #ENTRYPOINT ["wc", "-l"] #ENTRYPOINT ["echo", "running"] ENTRYPOINT mysqld_safe & sleep 10 #RUN mysql RUN echo "[mysqld]" >/etc/mysql/conf.d/docker.cnf RUN echo "bind-address = 0.0.0.0" >>/etc/mysql/conf.d/docker.cnf RUN echo "innodb_flush_method = O_DSYNC" >>/etc/mysql/conf.d/docker.cnf RUN echo "skip-name-resolve" >>/etc/mysql/conf.d/docker.cnf RUN echo "init_file = /etc/mysql/init" >>/etc/mysql/conf.d/docker.cnf RUN echo "GRANT ALL ON *.* TO root@ '%'" >/etc/mysql/init USER root EXPOSE 3306 

When starting this server using the command below

 sudo docker run -p 3306:13306 mysql/dockerfiletest 

An error has occurred:

 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 

Can anyone suggest what needs to be changed here. I want to use this container to communicate with another container, which essentially launches my Node.js application.

+6
source share
2 answers

UPDATE: You should check the exposed port number - in your example there is (was) a port for memcached (11211), and not a port for mysql (3306).


In any case, I think that you may need to modify your Docker file - delete unnecessary sleep at the entry point:

 ENTRYPOINT ["/usr/bin/mysqld_safe"] 

Then you should start the container this way (daemon mode):

 root@machine :/# docker run -d -p 3306:<host port> <image id> 
+2
source

the answer is already accepted, but I think you can leave the dream at your entry point if you change '&' to && '. not sure docker does any parsing of the entry point or just does it, but bash treats '&' very different from '& &'.

 ENTRYPOINT mysqld_safe && sleep 10 
+2
source

All Articles