Run Second MySQL Instance Using Docker
I wanted to create a separate MySQL instance running in my local machine. So decided to use Docker-Compose for Docker .
- Install docker-compose
2. create a docket compose file for mysql docker-compose.yml
3. Make sure your docker service is up and running
sudo service docker start
4. Create the image, run from the location where you created docker-compose.yml file
docker-compose up
If the task ends as above, then all is done, your mysql server is up and running
5. verify
mysql — port=3309 -uuser -phelloworld — protocol=TCP
6. stop and start: Next you can start and stop the container as following
docker-compose start
docker-compose stop
Going Deep
protocol=TCP is required to force to use new port if not it will use default port number and connect to local server instead. this is required only if you are connecting to local docker container.
ports:’3309:3306’ will map default mysql port 3306 to 3309. so we can access this instance via port 3309
volumes:mysql-db:/var/lib/mysql this will store the data locally in the pc. so when ever we recreate the container data will be persisted.