Skip to content

Instantly share code, notes, and snippets.

@oneamtu
Last active September 18, 2020 16:43
Show Gist options
  • Save oneamtu/41680a3db2b4d952e152 to your computer and use it in GitHub Desktop.
Save oneamtu/41680a3db2b4d952e152 to your computer and use it in GitHub Desktop.
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
# This folder houses the server data
sudo mkdir /data/
# 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
docker logs percona-5.6
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
# If you need to assign data folder permissions to docker
sudo mkdir /data/mysql-5.6
sudo chgrp docker /data/mysql-5.6
sudo chown 999 /data/mysql-5.6
# Install docker
# This sets a postgres-9.6 container to run continuously
# set ROOT_PGSQL_PASSWORD
export ROOT_PGSQL_PASSWORD="blah" #CHANGEME
# This folder houses the server data
sudo mkdir /data/
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
docker logs postgres-9.6
psql -U postgres -h 127.0.0.1
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