简体   繁体   中英

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.

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 .

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM