Mapping local volume and port binding for Postgres container in k8s/Skaffold

10/2/2019

I'm under the impression that the equivalent of the following command can't be put into a Dockerfile or Dockerfile.dev:

docker run -p 5432:5432 -v /home/app/database/db-files:/var/lib/postgresql/data sockpuppet/database

The -p 5432:5432 I was using to bind to the local port so I could connect to Postgres with pgAdmin. This is not an absolute requirement, but a nice to have. Perhaps there is a better way of doing this?

The -v /home/app/database/db-files:/var/lib/postgresql/data so I can persist data on the local volume.

The problem is EXPOSE in a Dockerfile, as far as I know, just opens ports between containers. The problem with VOLUME in a Dockerfile is that it just refers to the image's file system.

The bigger issue I'm having a hard time understanding is the Skaffold skaffold.yaml refers to these Dockerfile`Dockerfile.dev` when running the containers:

apiVersion: skaffold/v1beta2
kind: Config
build:
  local:
    push: false
  artifacts:
    - image: sockpuppet/client
      context: client
      docker:
        dockerfile: Dockerfile.dev
      sync:
        '**/*.js': .
        '**/*.css': .
        '**/*.html': .
    - image: sockpuppet/server
      context: server
      docker:
        dockerfile: Dockerfile.dev
      sync:
        '**/*.js': .
deploy:
  kubectl:
    manifests:
      - k8s/client-deployment.yaml
      - k8s/server-deployment.yaml
      - k8s/server-cluster-ip-service.yaml
      - k8s/client-cluster-ip-service.yaml

So how am I supposed to bind ports and map volumes if they can't be specified in Dockerfile? Do I just need to run docker run -p 5432:5432 -v /home/app/database/db-files:/var/lib/postgresql/data ishraqiyun77/database manually every time I want to start up the DB?

Repo I'm using as a reference if that is helpful: https://github.com/StephenGrider/DockerCasts/tree/master/complex

-- eox.dev
docker
dockerfile
kubernetes
postgresql
skaffold

1 Answer

10/2/2019

The skaffold.yaml is there to help with build and deployment of k8s. If you want to do port-exposing and volume mapping, you should do that in the various .yaml files in the manifests section. The EXPOSE keyword in your Dockerfiles simply tells the newly-created image which ports to allow for exposing and forwarding; it is only in your k8s containers that you actually do the mapping of ports and volumes to the host machine.

Disclosure: I am an EnterpriseDB (EDB) employee

-- richyen
Source: StackOverflow