How to pass docker run flags via kubernetes pod

Viewed 24518

Hi I am running kubernetes cluster where I run mailhog container.

But I need to run it with own docker run parameter. If I would run it in docker directly. I would use command:

docker run  mailhog/mailhog -auth-file=./auth.file

But I need to run it via Kubernetes pod. My pod looks like:

   apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: mailhog
    spec:
      replicas: 1
      revisionHistoryLimit: 1
      strategy:
          type: RollingUpdate
      template:
        metadata:
          labels:
            app: mailhog
        spec:
          containers:
          - name: mailhog
            image: us.gcr.io/com/mailhog:1.0.0
            ports:
            - containerPort: 8025

How to achieve to run Docker container with parameter -auth-file=./auth.file via kubernetes. Thanks.

I tried adding under containers

        command: ["-auth-file", "/data/mailhog/auth.file"]

but then I get

 Failed to start container with docker id 7565654 with error: Error response from daemon: Container command '-auth-file' not found or does not exist.
4 Answers

I needed similar task (my aim was passing the application profile to app) and what I did is the following:

Setting an environment variable in Deployment section of the kubernetes yml file.

env:
- name: PROFILE
  value: "dev"

Using this environment variable in dockerfile as command line argument.

CMD java -jar -Dspring.profiles.active=${PROFILE} /opt/app/xyz-service-*.jar 
Related