Monday, August 21, 2017

Running MySQL and Postgres in Docker

Yes, I know this is an Oracle DBA blog, but we have to keep up and learn new things.

With this in mind, I ran up MySQL and Postgres databases in Docker containers. It took about 30 minutes or so.

This assumes you have downloaded and installed Docker.

Start a Powershell session and type:

docker pull mysql

Once downloaded (only takes a few minutes), create the container by typing this on one line.

docker run --name andy-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=a_strong-password -d mysql:latest

So that is a MySQL database running in a Docker container.

Download MySQL Workbench (you will also need to install some prerequisites – just follow the instructions.


Start MySQL Workbench and select ‘Database / Connect to database’



Click on “OK”


It should prompt for the password:


Click “OK”


It will open a query window – click on “Server Status” to see the server info



This is in the right-hand pane:



There is also a Performance Dashboard


So that's it for MySQL.

Some useful Docker commands -

Stop (kill) any running containers:

docker kill $(docker ps -a -q)

Remove stopped containers:


docker rm $(docker ps -a -q)

Note that Docker containers are not persistent - any changes like adding users, tables or loading data will be lost when the container is stopped. You need to use the Docker 'COMMIT' command:

https://docs.docker.com/engine/reference/commandline/commit/


The process is the same for Postgres:

Open a Powershell session and type

docker pull postgres

Once downloaded, start the container by typing this on one line:

docker run --name andypg -e POSTGRES_PASSWORD=a_strong-password -d -p 5432:5432 postgres

Download the latest version of PgAdmin.

Start pgadmin and connect to Postgres:


Right-click on “Servers”, then”Create / Server”


Enter the name:



Click on the “Connection” tab, enter this information:


Click on “Save”.


Should appear in the list:


Click on it, stats appear in the right-hand pane:



That's it for Postgres. All very quick and easy, so get learning.




















No comments:

Post a Comment