<p>I need to copy some configuration files already present in a location B to a location A where I have mounted a persistent volume, in the same container.
for that I tried to configure a post start hook as follows</p>
<pre><code>    lifecycle:
      postStart:
        exec:
          command:
            - &quot;sh&quot;
            - &quot;-c&quot;
            - &gt;
              if [! -d &quot;/opt/A/data&quot; ] ; then
                cp -rp /opt/B/. /opt/A;
              fi;
              rm -rf /opt/B
</code></pre>
<p>but it exited with 126
Any tips please</p>

ar zi
<p>You should give a space after the first bracket <code>[</code>. The following <code>Deployment</code> works:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        lifecycle:
          postStart:
            exec:
              command:
                - &quot;sh&quot;
                - &quot;-c&quot;
                - &gt;
                  if [ ! -d &quot;/suren&quot; ] ; then
                    cp -rp /docker-entrypoint.sh /home/;
                  fi;
                  rm -rf /docker-entrypoint.sh
</code></pre>
<p>So, this nginx container starts with a <code>docker-entrypoint.sh</code> script by default. After the container has started, is won't find the directory <strong>suren</strong>, that will give <code>true</code> to the <code>if</code> statement, it will copy the script into <code>/home</code> directory and remove the script from the root.</p>
<pre><code># kubectl exec nginx-8d7cc6747-5nvwk 2&gt; /dev/null -- ls /home/
docker-entrypoint.sh
</code></pre>
