---
# System prepended metadata

title: postgres db docker compose

---

# postgres db docker compose

## Docker installtion on linux

1. [Install Docker Engine on CentOS](https://docs.docker.com/engine/install/centos/)
2. [Install Docker Engine on Ubuntu](https://docs.docker.com/engine/install/ubuntu/)

3. 
```shell
# Ubuntu
$ sudo apt install -y curl vim
# CentOS
$ sudo yum install -y curl vim


$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh

$ sudo docker --version
$ sudo docker ps
```

## docker compose

```shell
$ vim docker-compose.yml
```

docker-compose.yml
```yaml=
version: '3.1'

services:

  db:
    image: postgres:12-alpine
    restart: always
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: adminPASSwd
      POSTGRES_DB: appdb
    volumes:
      - dbdata:/var/lib/postgresql/data
    ports:
      - 5432:5432

  # adminer:
  #   image: adminer
  #   restart: always
  #   ports:
  #     - 8080:8080

volumes:
  dbdata:
```

```shell
$ docker compose pull
# 下載 images

$ docker compose up -d
# 在背景啟動所有服務

$ docker compose ps
# 顯示所有服務狀態

$ docker compose logs -f db
# 顯示 mongo 服務 log


$ docker compose down
# 停止並移除所有服務

$ docker volume ls

$ docker volume rm xxxx-dbdata
```


