読者です 読者をやめる 読者になる 読者になる

AKAI TSUKI

System development or Technical something

Use PostgreSQL in docker.

PostgreSQL
https://hub.docker.com/r/library/postgres/

start a postgres instance

[root@docker01 ~]# docker run --name some-postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres
Unable to find image 'postgres:latest' locally
latest: Pulling from library/postgres
5c90d4a2d1a8: Pull complete
22337bfd13a9: Pull complete
c3961b297acc: Pull complete
5a17453338b4: Pull complete
6364e0d7a283: Pull complete
58c25f5c0dad: Pull complete
f0e675ce88d9: Pull complete
10f26c680a34: Pull complete
873d2c220bff: Pull complete
fd10fb78ded6: Pull complete
ff1356ba118b: Pull complete
Digest: sha256:e0a230a9f5b4e1b8b03bb3e8cf7322b0e42b7838c5c87f4545edb48f5eb8f077
Status: Downloaded newer image for postgres:latest
c54fb96f7c51e717c693190576d3f319e4fc17500c4da46f0ef74478bb9fe12a
[root@docker01 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
c54fb96f7c51        postgres            "/docker-entrypoint.s"   5 seconds ago       Up 4 seconds        0.0.0.0:5432->5432/tcp   some-postgres
[root@docker01 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
postgres            latest              7ee9d2061970        3 weeks ago         275.2 MB
[root@docker01 ~]#

connect to postgres instance via psql.

[root@docker01 ~]# docker run -it --rm --link some-postgres:postgres postgres psql -h postgres -U postgres
Password for user postgres:
psql (9.5.3)
Type "help" for help.

postgres-# \l
                                 List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges
-----------+----------+----------+------------+------------+-----------------------
 postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
 template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
(3 rows)

postgres-#