<p>In our docker-compose.yaml we have:</p>

<pre><code>version: "3.5"
services:
  consul-server:
    image: consul:latest
    command: "agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -config-dir=./usr/src/app/consul.d/"
    volumes:
      - ./consul.d/:/usr/src/app/consul.d
</code></pre>

<p>In the <code>consul.d</code> folder we have statically defined our services. It works fine with docker-compose.</p>

<p>But when trying to run it on Kubernetes with this configmap:</p>

<pre><code>ahmad@ahmad-pc:~$ kubectl describe configmap consul-config -n staging
Name:         consul-config
Namespace:    staging
Labels:       &lt;none&gt;
Annotations:  &lt;none&gt;

Data
====
trip.json:
----
... omitted for clarity ...
</code></pre>

<p>and consul.yaml:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    io.kompose.service: consul-server
  name: consul-server
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: consul-server
  template:
    metadata:
      labels:
        io.kompose.service: consul-server
    spec:
      containers:
      - image: quay.io/bitnami/consul:latest
        name: consul-server
        ports:
        - containerPort: 8500
        #env:
        #- name: CONSUL_CONF_DIR # Consul seems not respecting this env variable
        #  value: /consul/conf/
        volumeMounts:
        - name: config-volume
          mountPath: /consul/conf/
        command: ["agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -config-dir=/consul/conf/"]
      volumes:
        - name: config-volume
          configMap:
            name: consul-config
</code></pre>

<p>I got the following error:</p>

<pre><code>ahmad@ahmad-pc:~$ kubectl describe pod consul-server-7489787fc7-8qzhh -n staging
...

Error: failed to start container "consul-server": Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -config-dir=/consul/conf/\": 
stat agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -config-dir=/consul/conf/: 
no such file or directory": unknown
</code></pre>

<p>But when I run the container without <code>command: agent...</code> and bash into it, I can list files mounted in the right place.
Why consul gives me a not found error despite that folder exists?</p>

Ahmad Ahmadi
<p>To <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#define-a-command-and-arguments-when-you-create-a-pod" rel="nofollow noreferrer">execute command</a> in the pod you have to define a command in <code>command</code> field and arguments for the command in <code>args</code> field.  <code>command</code> field is the same as <code>ENTRYPOINT</code> in Docker and <code>args</code> field is the same as <code>CMD</code>.<br>
In this case you define <code>/bin/sh</code> as ENTRYPOINT and <code>"-c, "consul agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -data-dir=/bitnami/consul/data/ -config-dir=/consul/conf/"</code> as arguments so it can execute <code>consul agent ...</code>:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    io.kompose.service: consul-server
  name: consul-server
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: consul-server
  template:
    metadata:
      labels:
        io.kompose.service: consul-server
    spec:
      containers:
      - image: quay.io/bitnami/consul:latest
        name: consul-server
        ports:
        - containerPort: 8500
        env:
        - name: CONSUL_CONF_DIR # Consul seems not respecting this env variable
          value: /consul/conf/  
        volumeMounts:
        - name: config-volume
          mountPath: /consul/conf/
        command: ["bin/sh"]
        args: ["-c", "consul agent -server -bootstrap -ui -enable-script-checks=true -client=0.0.0.0 -data-dir=/bitnami/consul/data/ -config-dir=/consul/conf/"] 
      volumes:
        - name: config-volume
          configMap:
            name: consul-config
</code></pre>
