Skip to content

Commit

Permalink
Move scripts to a directory to simplify installation
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrs committed Nov 19, 2024
1 parent f9bd8ec commit 8aa6195
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ You can add the scripts to your images like this:
FROM alpine

ARG DOCKER_SCRIPTS_VERSION=0.2.0
ADD --chmod=755 https://github.com/felipecrs/docker-scripts/raw/v${DOCKER_SCRIPTS_VERSION}/get_cpus.sh /opt/docker-scripts/
ADD --chmod=755 https://github.com/felipecrs/docker-scripts/raw/v${DOCKER_SCRIPTS_VERSION}/get_memory.sh /opt/docker-scripts/
ADD --chmod=755 https://github.com/felipecrs/docker-scripts/raw/v${DOCKER_SCRIPTS_VERSION}/is_privileged.sh /opt/docker-scripts/
ADD https://github.com/felipecrs/docker-scripts/archive/refs/tags/v${DOCKER_SCRIPTS_VERSION}.tar.gz /opt/docker-scripts
```

And then, you can invoke any script calling it from their path:
And then, you can invoke any script calling it from `/opt/docker-scripts`:

```console
docker run --rm --cpus 2 my-image /opt/docker-scripts/get_cpus.sh
Expand All @@ -39,23 +37,23 @@ And then, you can invoke any script calling it from their path:
In a system with cgroup v2:

```console
cat get_cpus.sh | docker run --rm -i -e VERBOSE=true alpine sh
cat scripts/get_cpus.sh | docker run --rm -i -e VERBOSE=true alpine sh
VERBOSE(get_cpus.sh): cgroup v2 detected.
VERBOSE(get_cpus.sh): No CPU limits set.
VERBOSE(get_cpus.sh): CPUs:
16

cat get_cpus.sh | docker run --rm -i -e VERBOSE=true --cpus 2 alpine sh
cat scripts/get_cpus.sh | docker run --rm -i -e VERBOSE=true --cpus 2 alpine sh
VERBOSE(get_cpus.sh): cgroup v2 detected.
VERBOSE(get_cpus.sh): CPUs:
2

cat get_cpus.sh | docker run --rm -i -e VERBOSE=true --cpus 1.5 alpine sh
cat scripts/get_cpus.sh | docker run --rm -i -e VERBOSE=true --cpus 1.5 alpine sh
VERBOSE(get_cpus.sh): cgroup v2 detected.
VERBOSE(get_cpus.sh): CPUs:
1

cat get_cpus.sh | docker run --rm -i -e VERBOSE=true --cpus 0.5 alpine sh
cat scripts/get_cpus.sh | docker run --rm -i -e VERBOSE=true --cpus 0.5 alpine sh
VERBOSE(get_cpus.sh): cgroup v2 detected.
VERBOSE(get_cpus.sh): CPUs:
1
Expand All @@ -64,23 +62,23 @@ VERBOSE(get_cpus.sh): CPUs:
Another system with cgroup v1:

```console
cat get_cpus.sh | docker run --rm -i -e VERBOSE=true alpine sh
cat scripts/get_cpus.sh | docker run --rm -i -e VERBOSE=true alpine sh
VERBOSE(get_cpus.sh): cgroup v1 detected.
VERBOSE(get_cpus.sh): No CPU limits set.
VERBOSE(get_cpus.sh): CPUs:
8

cat get_cpus.sh | docker run --rm -i -e VERBOSE=true --cpus 2 alpine sh
cat scripts/get_cpus.sh | docker run --rm -i -e VERBOSE=true --cpus 2 alpine sh
VERBOSE(get_cpus.sh): cgroup v1 detected.
VERBOSE(get_cpus.sh): CPUs:
2

cat get_cpus.sh | docker run --rm -i -e VERBOSE=true --cpus 1.5 alpine sh
cat scripts/get_cpus.sh | docker run --rm -i -e VERBOSE=true --cpus 1.5 alpine sh
VERBOSE(get_cpus.sh): cgroup v1 detected.
VERBOSE(get_cpus.sh): CPUs:
1

cat get_cpus.sh | docker run --rm -i -e VERBOSE=true --cpus 0.5 alpine sh
cat scripts/get_cpus.sh | docker run --rm -i -e VERBOSE=true --cpus 0.5 alpine sh
VERBOSE(get_cpus.sh): cgroup v1 detected.
VERBOSE(get_cpus.sh): CPUs:
1
Expand All @@ -91,13 +89,13 @@ VERBOSE(get_cpus.sh): CPUs:
In a system with cgroup v2:

```console
cat get_memory.sh | docker run --rm -i -e VERBOSE=true alpine sh
cat scripts/get_memory.sh | docker run --rm -i -e VERBOSE=true alpine sh
VERBOSE(get_memory.sh): cgroup v2 detected.
VERBOSE(get_memory.sh): No memory limits set.
VERBOSE(get_memory.sh): Memory (MB):
15996

cat get_memory.sh | docker run --rm -i -e VERBOSE=true --memory 1g alpine sh
cat scripts/get_memory.sh | docker run --rm -i -e VERBOSE=true --memory 1g alpine sh
VERBOSE(get_memory.sh): cgroup v2 detected.
VERBOSE(get_memory.sh): Memory (MB):
1024
Expand All @@ -106,13 +104,13 @@ VERBOSE(get_memory.sh): Memory (MB):
Another system with cgroup v1:

```console
cat get_memory.sh | docker run --rm -i -e VERBOSE=true alpine sh
cat scripts/get_memory.sh | docker run --rm -i -e VERBOSE=true alpine sh
VERBOSE(get_memory.sh): cgroup v1 detected.
VERBOSE(get_memory.sh): No memory limits set.
Memory (MB):
32092

cat get_memory.sh | docker run --rm -i -e VERBOSE=true --memory 1g alpine sh
cat scripts/get_memory.sh | docker run --rm -i -e VERBOSE=true --memory 1g alpine sh
VERBOSE(get_memory.sh): cgroup v1 detected.
VERBOSE(get_memory.sh): Memory (MB):
1024
Expand All @@ -121,12 +119,12 @@ VERBOSE(get_memory.sh): Memory (MB):
### `is_privileged.sh`

```console
cat is_privileged.sh | docker run --rm -i -e VERBOSE=true alpine sh
cat scripts/is_privileged.sh | docker run --rm -i -e VERBOSE=true alpine sh
VERBOSE(is_privileged.sh): Container is not running in privileged mode.
echo $?
1

cat is_privileged.sh | docker run --rm -i -e VERBOSE=true --privileged alpine sh
cat scripts/is_privileged.sh | docker run --rm -i -e VERBOSE=true --privileged alpine sh
VERBOSE(is_privileged.sh): Container is running in privileged mode.
echo $?
0
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8aa6195

Please sign in to comment.