Last Update: 6/24/2024
This is a LIVE version of a post. This is being edited.
services:
db:
image: postgres
restart: always
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: p@$$w0rd
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- 5432:5432
volumes:
pgdata:
There are two relatively competing images that aid in the administration of docker.
- admin
- pgadmin
adminer:
image: adminer
restart: always
ports:
- 8080:8080
if you have to force set the postgres username/password
postgres=# ALTER USER postgres PASSWORD 'p@$$w0rd';
creating a small table
CREATE TABLE assets (
AssetID int,
hostname varchar(255),
osfamily varchar(255),
ipaddress varchar(255),
tag varchar(255)
);
inserting some basic info
INSERT INTO assets (AssetID, hostname, osfamily, ipaddress, tag)
VALUES(1,'NY-0001', 'NT_WORKSTATION','172.16.15.2','');
Using python to access postgres.
import pg8000.native
con = pg8000.native.Connection("postgres", password="p@$$w0rd")
for row in con.run("SELECT * FROM assets;"):
print(row)
more
apt install postgresql-client-common
apt install postgresql-client
acessing docker image
docker exec -it 28a /bin/bash