How to deploy and use a MySQL Docker container in Ubuntu
2 min readSep 29, 2018
- First, we have to install docker in your machine to deploy a MySql docker container.
Pulling the image
- We need to pull down the correct image. To this, we need to give the MySQL version and we can use below command. By this way, we can pull mysql-server:5.7 image.
sudo docker pull mysql/mysql-server:5.7
Deploying the container
- To deploy the MySQL container we can use the following command. mysqlCon is the container name which is trying to deploy.
sudo docker run --name=mysqlCon -p 3306:3306 -d mysql/mysql-server:5.7
- When deploying a Docker container that already has the database installed and running. To use those databases you need to set a password. During the deployment, a random password will have been generated. We can see that password using below command.
sudo docker logs mysqlCon
- We can login to the containerized MySql server from below command.
sudo docker exec -it mysqlCon mysql -uroot -p
- After giving the received password from docker logs mysqlCon command we can login to the MySql server.
- After login to MySql server, we can change the password using below command.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
- We can give all the permissions to “root” user using below command.
GRANT ALL PRIVILEGES ON *.* to root@'%' IDENTIFIED BY 'root';
Then we can create databases and connections and so on.