> For the complete documentation index, see [llms.txt](https://hossainemruz.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hossainemruz.gitbook.io/notes/kubernetes/untitled/container/inject-executable-script.md).

# Inject Executable Script

## How to Inject an Executable Script into a Container?

Let's we want to execute a script inside a container. The script is not not a part of the docker image. We have to inject script then execute it.

**Solution:**

1. Create a configMap with the script.
2. Mount the configMap to the container as a volume with `defaultMode: 0744`.
3. Use `command:["/path/to/the/script.sh"]` to run the script.

```yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: ghost
  labels:
    role: blog
spec:
  replicas: 1
  template:
    metadata:
      labels:
        role: blog
    spec:
      containers:
      - name: ghost
        image: ghost:0.11-alpine
        command: ["/scripts/wrapper.sh"]
        ports:
        - name: ghost
          containerPort: 2368
          protocol: TCP
        volumeMounts:
        - name: wrapper
          mountPath: /scripts
      volumes:
      - name: wrapper
        configMap:
          name: wrapper
          defaultMode: 0744
```
