# Container do PostgreSQL

Será utilizado o volume gerenciado pelo Docker:

```bash
$ docker volume create kube-news
kube-news
$ docker volume ls
DRIVER    VOLUME NAME
local     kube-news
```

Criação do container com portbind, conexão à rede kube-news e mapeamento do volume:

<figure><img src="https://2056950903-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7JJDMtYZqFc5W4Gd6mo1%2Fuploads%2Fi7lNi3CSymYovP5jbwXi%2Fimage.png?alt=media&#x26;token=7e5d9d39-5ad1-4da2-8f85-2e8599de2210" alt=""><figcaption></figcaption></figure>

```bash
$ docker container run -d -p 5432:5432 \
    --name kube-news-db \
    -e POSTGRES_PASSWORD=kube-news \
    -e POSTGRES_USER=kube-news \
    -e POSTGRES_DB=kube-news \
    --network kube-news \
    --mount type=volume,source=kube-news,target=/var/lib/postgresql/data \    
    postgres:13.16
    
Unable to find image 'postgres:13.16' locally
13.16: Pulling from library/postgres
e4fff0779e6d: Pull complete
6cf30cfc822c: Pull complete
af1d574c3ad1: Pull complete
9770b3362dda: Pull complete
dda3697c5b16: Pull complete
f198a7595590: Pull complete
eb4191d05878: Pull complete
1d0eb8a8dbad: Pull complete
66f0b6ddcec2: Pull complete
66c9ebb47429: Pull complete
eea6f96f604b: Pull complete
b7c08779da16: Pull complete
32dc030c5211: Pull complete
32ceea7ae699: Pull complete
Digest: sha256:0b66ab08973087a4592632a719e6b83357bf63a5db4f92ae507cbe0037cbdd85
Status: Downloaded newer image for postgres:13.16
d05071c8b7c09b063b1f1699493b36a2cbf54eac7de03ea1f5c9198a1d5ed917    
```

{% embed url="<https://hub.docker.com/layers/library/postgres/13.16/images/sha256-092fb93dfed297fbfb645f17fb101fedf3067135ccea7eb693f8305c23af2195?context=explore>" %}

O mapeamento do volume poderia ter sido feito com:

```bash
-v kube-news:/var/lib/postgresql/data
```

Container criado:

```bash
$ docker container ls
CONTAINER ID   IMAGE            COMMAND                  CREATED          STATUS          PORTS
              NAMES
d05071c8b7c0   postgres:13.16   "docker-entrypoint.s…"   28 seconds ago   Up 27 seconds   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp   kube-news-db
```

Teste de conexão:

<figure><img src="https://2056950903-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7JJDMtYZqFc5W4Gd6mo1%2Fuploads%2FZDisA1Gv2sj8QCxw3qwq%2Fimage.png?alt=media&#x26;token=b4fb075e-e6a7-4cf8-84f6-6803093f79e1" alt=""><figcaption></figcaption></figure>
