Mark Taylor
Mark Taylor

Reputation: 371

How to start mysql server in docker container

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.

Upvotes: 25

Views: 54824

Answers (3)

Emms Magdy
Emms Magdy

Reputation: 21

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

Upvotes: 2

Sindhu
Sindhu

Reputation: 2582

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

Upvotes: 3

Henrik Sachse
Henrik Sachse

Reputation: 54212

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.

Upvotes: 28

Related Questions