Skip to content

Instantly share code, notes, and snippets.

@oneamtu oneamtu/mysql_docker.sh
Last active Nov 1, 2019

Embed
What would you like to do?
set up docker persistent database instance for development
# Install docker
# This sets a percona-5.6 container to run continuously
# set ROOT_MYSQL_PASSWORD
export ROOT_MYSQL_PASSWORD="blah" #CHANGEME
sudo docker pull percona:5.6
# To run the daemon
sudo docker run --restart unless-stopped --name percona-5.6 -p 127.0.0.1:3306:3306 -v /data/mysql-5.6:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=$ROOT_MYSQL_PASSWORD -d percona:5.6
# To check
docker ps
mysql -u root -p$(echo $ROOT_MYSQL_PASSWORD) -h 127.0.0.1
sudo docker run -it --link percona-5.6:mysql --rm percona sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -u$(echo $ROOT_MYSQL_USER) -p$(echo $ROOT_MYSQL_PASSWORD)'
docker start percona:5.6
docker stop percona:5.6
# Install docker
# This sets a postgres-9.6 container to run continuously
# set ROOT_PGSQL_PASSWORD
export ROOT_PGSQL_PASSWORD="blah" #CHANGEME
sudo docker run --restart unless-stopped -p 127.0.0.1:5432:5432 -v /data/postgres-9.6:/var/lib/postgresql/data/pgdata -e POSTGRES_PASSWORD=$ROOT_PGSQL_PASSWORD -e PGDATA=/var/lib/postgresql/data/pgdata --name postgres-9.6 -d postgres:9.6.9
# To check
docker ps
psql -U postgres
docker run -it --link postgres:postgres --rm postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'
# To start/stop
docker start postgres-9.6
docker stop postgres-9.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.