Thursday, July 25, 2019

PostgreSQL docker using Docker Compose

Create a docker-compose.yml file like below:

version: '3'

services:
  db:
    image: postgres:latest
    restart: always
    ports:
      - 5432:5432
    environment:
      POSTGRES_PASSWORD: 'postgres'
    volumes:
      - database_data:/var/lib/postgresql/data

volumes:
  database_data:
    driver: local

User below command to start docker compose:

docker-compose up

Install pgAdmin client to connect started PostgreSQL docker:







Wednesday, July 24, 2019

Vault Docker CLI commands


  • Create app role:
curl -X POST -H "X-Vault-Token:${vault-token}" -d '{"type":"approle"}' http://127.0.0.1:8200/v1/sys/auth/approle
  • Add policies:
curl -X POST -H "X-Vault-Token:${vault-token}" -d '{"policies":"dev-policy,test-policy"}' http://127.0.0.1:8200/v1/auth/approle/role/testrole
  • Get role id and secret:
curl -X GET -H "X-Vault-Token:${vault-token}" http://127.0.0.1:8200/v1/auth/approle/role/testrole/role-id | jq .

curl -X POST -H "X-Vault-Token:${vault-token}" http://127.0.0.1:8200/v1/auth/approle/role/testrole/secret-id | jq .
  • Get client token:
curl -X POST -d '{"role_id":"${role-id}","secret_id":"${secret-id}"}' http://127.0.0.1:8200/v1/auth/approle/login | jq .
  • Create kv engine mount:
tee payload.json <<EOF
{
  "type": "kv",
  "options": {
    "version": "1"
  }
}
EOF

curl --header "X-Vault-Token:${vault-token}" --request POST --data @payload.json http://127.0.0.1:8200/v1/sys/mounts/secret

  • Store data:
tee payload.json <<EOF
{
  "value": "localhost"
}
EOF

curl --header "X-Vault-Token:${vault-token}" --request POST --data @payload.json http://127.0.0.1:8200/v1/secret/dev/esb.host

tee payload.json <<EOF
{
  "value": "9443"
}
EOF

curl --header "X-Vault-Token:${vault-token}" --request POST --data @payload.json http://127.0.0.1:8200/v1/secret/dev/esb.port


  • Retrieve data:
curl -H "X-Vault-Token:${vault-token}" http://127.0.0.1:8200/v1/secret/dev/esb.host | jq .data.value | sed 's/"//g'

curl -H "X-Vault-Token:${vault-token}" http://127.0.0.1:8200/v1/secret/dev/esb.port | jq .data.value | sed 's/"//g'


Vault Docker setup in local using Docker Compose

1. Create folder called "vault-docker"
2. Create Following file structure inside that folder

3. Inside volume folder:
4. Inside config folder:
5. Create a docker-composer.yml file and fill it like below:

version: '3'
services:
  vault:
    image: vault
    container_name: vault
    ports:
      - "8200:8200"
    restart: always
    volumes:
      - /home/prabod/UOE/vault-docker/volumes/config:/vault/config
      - /home/prabod/UOE/valut-docker/volumes/logs:/vault/logs
      - /home/prabod/UOE/valut-docker/volumes/file:/vault/file
    cap_add:
      - IPC_LOCK
    entrypoint: vault server -config=/vault/config/vault.json

Note: Please update above highlighted path as your.

6. Create a vault.json file and fill it like below:

{
  "backend": {
    "file": {
      "path": "/vault/file"
    }
  },
  "listener": {
    "tcp":{
      "address": "0.0.0.0:8200", # Listener host and port
      "tls_disable": 1
    }
  },
  "ui": true  # Enable UI
}

After creating all files and folders, Open terminal and navigate the location to vault-docker folder and run below command to up docker composer

docker-compose up

After successfully start docker vault, You should be able to login into the vault UI:

http://localhost:8200/ui/



Then create a vault token for you login.