Kill all running docker containers
docker ps -aq | xargs -r docker stop; docker ps -aq | xargs -r docker rm
Start a MySQL server
Very Important is the flag MYSQL_ROOT_HOST
is set to %
.
docker run -d --name=local-mysql -p 54321:3306 -e MYSQL_ROOT_HOST=% -e MYSQL_ROOT_PASSWORD=password mysql/mysql-server
Connect to MySQL using mac's mysql
export PATH="$PATH:/usr/local/mysql/bin"
# restart shell if required
mysql -h 127.0.0.1 -P 54321 -u root -ppassword
Docker Compose Setup
version: '3'
services:
db:
image: mysql:5.7
container_name: db
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_ROOT_HOST: '%'
ports:
- "54321:3306"
volumes:
- dbdata:/var/lib/mysql
volumes:
dbdata:
Save the above file as docker-compose.yaml
. Then run the following commands to start/stop the container. The container will persist data across restarts. If you want to clean up the volume use docker-compose down -v
command.
docker-compose up
docker-compose up -d # runs in the background
docker-compose down
docker-compose down -v
Top comments (0)