Run script into Docker

  bash, docker, linux

I have Dockerfile

FROM ubuntu:20.04
RUN apt-get update && apt-get install -y software-properties-common curl gnupg2 && 
  curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add - && 
  apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" && 
  apt-get update && apt-get install -y 
  vault && 
  setcap cap_ipc_lock= /usr/bin/vault

COPY run.sh ./

CMD ./run.sh

And my run.sh file

#!/bin/bash

VAULT_RETRIES=5
echo "Vault is starting..."
until vault status > /dev/null 2>&1 || [ "$VAULT_RETRIES" -eq 0 ]; do
        echo "Waiting for vault to start...: $((VAULT_RETRIES--))"
        sleep 1
done

echo "Authenticating to vault..."
vault login token=vault-plaintext-root-token

echo "Initializing vault..."
vault secrets enable -version=2 -path=my.secrets kv

echo "Adding entries..."
vault kv put my.secrets/dev username=test_user
vault kv put my.secrets/dev password=test_password

echo "Complete..."

When i run docker i have problem –

/bin/sh: 1: ./run.sh: not found

If i replace

CMD ./run.sh

on

RUN chmod +x run.sh

container runs without issues, but script is not worked, because i don’t see in terminal echo commands

Source: Docker Questions

LEAVE A COMMENT