# Docker Container Execute on Host Client/Server App

[![pknw1logo-white.png](https://bookstack.notflix.pknw1.co.uk/uploads/images/gallery/2025-01/scaled-1680-/HLPpknw1logo-white-png.png)](https://bookstack.notflix.pknw1.co.uk/uploads/images/gallery/2025-01/scaled-1680-/HLPpknw1logo-white-png.png)

##### `<span class="editor-theme-code">/usr/local/bin/pipe-exec</span>`

##### `<span class="editor-theme-code">/usr/local/bin/pipe-response</span>`

<u>****Client Server App for Host execution from within docker****</u>

The app runs in the container and uses fifo pipes to pass commands to the server side of the app running on the docker host; the commands are executed and responses piped back to the container

****Server Side Component****

```
#!/bin/bash
# /usr/local/bin/pipe-exec
# server side of app

if ! [[ -p /var/run/exec ]]
then
  [[ -d /var/run/exec ]] && rm -rf /var/run/exec 
  mkfifo /var/run/exec || echo "error" && exit 99
fi


if ! [[ -p /var/run/response ]]
then
  [[ -d /var/run/response ]] && rm -rf /var/run/response
  mkfifo /var/run/response || echo "error" && exit 99
fi

while true; do eval "$(cat /var/run/exec)" > /var/run/response; done
```

<details id="bkmrk-script-infocheck-mar">- [ ] pipe-exec runs on a docker host
- [ ] <span style="white-space: pre-wrap;">listens to fifo pipe /var/run/exec </span>
- [ ] creates pipe if doesnmt exist
- [ ] executes the data from the pipe on the docker host
- [ ] sends output of the command to fifo pipe /var/run/response
- [ ] ideally run server component as a service

```
# systemd service file to run pipe-exec on startup
# /etc/systemd/system/pipe_exec.service

[Unit]
Description=Pipe Exec

[Service]
Type=simple
ExecStart=/usr/local/bin/pipe-exec

[Install]
WantedBy=multi-user.target

```

</details>```
#!/bin/bash
# client side of app
# /usr/local/bin/pipe-response

echo "$1 $2 $3" > /var/run/exec
cat /var/run/response
```

****Client Application for inclusion and execution within docker container****

<details id="bkmrk-pipe-response-should">- [ ] `<span class="editor-theme-code">pipe-response</span>`<span style="white-space: pre-wrap;"> should be on the docker contaoner filesystem or mapped in as a volume</span>
- [ ] `<span class="editor-theme-code">/var/run/exec</span>`<span style="white-space: pre-wrap;"> must be mapped as a volume</span>
- [ ] `<span class="editor-theme-code">/var/run/response </span>`must be mapped in as a volume

```
# example docker-compose.yml for mapping folders and script
# within the container pass commands as
# pipe-response curl ifconfig.me
# returns host IP

---
services:
  your_container:
    container_name: your_container
    image: jamesread/your_container
    user: root
    volumes:
      - ./config/your_container:/config 
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/run/exec:/var/run/exec
      - /var/run/response:/var/run/response:ro
      - ./config/pipe-response:/usr/bin/pipe-response:ro
    restart: unless-stopped
    networks:
      - admin
    environment:
      - VIRTUAL_HOST=your_container.admin.pknw1.co.uk
      - VIRTUAL_PORT=1337

networks:
  admin:
    external: true
    name: admin

```

</details><u>****further info****</u>

<details id="bkmrk-product-homelinkdocu"><table><colgroup><col style="width: 240px;"></col><col style="width: 240px;"></col></colgroup><tbody><tr><td><u>****Product Home****</u>

</td><td>[Link](https://www.pknw1.co.uk)

</td></tr><tr><td><u>****Documentation****</u>

</td><td>[Link](https://www.pknw1.co.uk)

</td></tr><tr><td><u>****Github****</u>

</td><td>[Link](https://www.pknw1.co.uk)

</td></tr><tr><td><u>****DockerHub****</u>

</td><td>[Link](https://www.pknw1.co.uk)

</td></tr><tr><td><u>****Misc****</u>

</td><td>[Link](https://www.pknw1.co.uk)

</td></tr></tbody></table>

</details>more text more text