Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql installation on docker container

Tags:

docker

mysql

I am trying to run mysql into modified ubuntu image which includs installation of Node.js and 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

On running this server using below command

sudo docker run -p 3306:13306 mysql/dockerfiletest

Following error was encountered

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

Can some one please suggest what is needed to be changed here. I want to use this container to be linked with other container which is essentially running my node.js app.

like image 849
Hitesh Avatar asked Feb 10 '14 06:02

Hitesh


People also ask

Should you run MySQL in Docker?

Running MySQL with Docker containers is a widely used mechanism. MySQL is one of the most popular databases used with Docker containers. Of course, the host machine should have Docker installed for creating MySQL as a Docker container.


2 Answers

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


Anyway, I think that you may need to modify your Dockerfile - remove unnecessary sleep in entrypoint:

ENTRYPOINT ["/usr/bin/mysqld_safe"]

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

root@machine:/# docker run -d -p 3306:<host port> <image id>
like image 85
Jiri Avatar answered Nov 04 '22 04:11

Jiri


answer has already been accepted, but i think you could leave the sleep in your entrypoint if you change the '&' to '&&'. not sure if docker does any parsing of the entrypoint or just executes it, but bash treats '&' very differently than '&&'.

ENTRYPOINT mysqld_safe && sleep 10
like image 44
j-mo Avatar answered Nov 04 '22 03:11

j-mo