Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start mysql server in docker container

Tags:

I am creating docker container and base image is ubuntu:14.04. I have to start mysql server in that container and then I have to create databases and I have to give the permission to the users. Docker is new for me. I tried a lot but still whenever I go to that image and check for mysql server is running or not. Every time what I got is mysql server is stopped and my dbs are also not created. This is my dockerfile

FROM ubuntu:14.04
MAINTAINER <name> <emailid>
RUN sudo apt-get update
RUN sudo apt-get install -y apache2 mysql-server libapache2-mod-auth-mysql php5-mysql php5 git
RUN sudo apt-get install -y vim
CMD sudo /usr/sbin/mysqld -u mysql

I tried a lot but i am not able to run mysql server in docker image.

like image 900
Mark Taylor Avatar asked Aug 10 '15 11:08

Mark Taylor


3 Answers

Did you manually install it in your container?

Why do you not simply use:

docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=mySchema mysql:5 

That would start a container named mysql running a mysql daemon, setting the default root password to secret, creating a new schema called mySchema and expose the MySQL port 3306 to clients so that they could connect.

Then you could connect to that with any MySQL client using the root user with the specified password secret and create your tables within the created schema mySchema.

like image 109
Henrik Sachse Avatar answered Oct 25 '22 05:10

Henrik Sachse


I had similar issue for ubuntu :14.04 while setting up druid cluster in the docker container, using CMD to start mysql fixed it for me.

CMD mysql start \

Druid related stuff

&& mysql stop
like image 22
Sindhu Avatar answered Oct 25 '22 05:10

Sindhu


docker exec -it container_name/id bash
service mysql status to check on the service status
service mysql start to start the mysql service

like image 30
Emms Magdy Avatar answered Oct 25 '22 03:10

Emms Magdy