Last active
October 19, 2022 06:58
-
-
Save alirezaarzehgar/b911ee6469bb6dfa7ff2f3f65dfdede9 to your computer and use it in GitHub Desktop.
Example for using entrypoints on docker containers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| #set -x | |
| [[ $(docker ps --all --filter=name=example-ps -q) ]] && exit | |
| # create local files for coping on docker container | |
| echo '#!/bin/sh | |
| echo "Hello, Entrypoint" | |
| for dir in $(ls /root/daemons/*); do | |
| sh $dir & | |
| done | |
| yes > /dev/null' > init.sh | |
| echo '#!/bin/sh | |
| filename=$(basename $0) | |
| sectemp=${filename#daemon} | |
| while [ 1 ]; do | |
| echo ${filename%.sh} | |
| sleep ${sectemp%.sh} | |
| done' > daemon.sh | |
| daemons_fmt=daemons/daemon | |
| mkdir -p daemons | |
| chmod +x init.sh daemon.sh | |
| for i in $(seq 3); do | |
| cp daemon.sh ${daemons_fmt}${i}.sh | |
| done | |
| # create docker container run and remove it | |
| docker create -it --name example-ps --entrypoint="/root/init.sh" busybox:1.29 | |
| docker cp init.sh example-ps:/root | |
| docker cp daemons example-ps:/root | |
| docker start --interactive example-ps | |
| docker rm -f example-ps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment