This walks you through:
- Running Postgres locally in a docker container using docker networking (rather than the deprecated container links functionality that is mentioned in the Postgres Docker instructions.
- Deploying to Docker Cloud
Basic Postgres container with docker networking
Create a user defined network
1
|
|
Launch Postgres in that network
The main parameter you will need to provide to postgres is a root db password. Replace *********
with a good password and run this command:
1
|
|
Launch psql and connect to Postgres
1 2 3 4 5 6 |
|
You now have a working postgres database server.
Using a mounted volume for persistence
When running postgres under docker, most likely want to persist the database files on the host, rather than having them in the container.
First, remove the previous container with:
1
|
|
Go into the /tmp
directory:
1
|
|
Launch a container and use /tmp/pgdata
as the host directory to mount as a volume mount, which will be mounted in the container in /var/lib/postgresql/data
, which is the default location where Postgres stores it’s data. The /tmp/pgdata
directory will be created on the host if it doesn’t already exist.
1
|
|
List the contents of /tmp/pgdata
and you should see several Postgres files:
1 2 |
|
Launch phppgadmin Container
First create a user
1
|
|
Now you will be in a shell inside the docker container
1 2 3 4 |
|
Launch pgpadmin
1
|
|
Login
In your browser, open http://localhost:8080/ and you should see the phpadmin login screen:
Login with user/pass credentials created earlier:
- username:
testuser
- password:
**********
Deploying to Docker Cloud
Security warning! This is not a secure deployment and it’s not recommended to run this in production without a thorough audit by a security specialist.
Deploy Stack
Create a new stack and paste it into the box
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
For example:
Create user
Find the postgres-server container and hit the Terminal menu to get a shell on that container.
Enter:
1 2 3 |
|
Login to Web UI
Find the phppgadmin service in the Docker Cloud Web UI, and look for the service endpoint, which should look something like this:
http://phppgadmin.postgres.071a32d40.svc.dockerapp.io:8085/
Login with user/pass credentials created earlier:
- username:
testuser
- password:
**********