mirror of
https://github.com/p8952/bocker.git
synced 2025-11-08 23:43:59 +01:00
Implement 'bocker pull' for Docker Hub integration
This commit is contained in:
parent
d5b38393c2
commit
b240a47ac8
61
README.md
61
README.md
@ -12,6 +12,7 @@ Docker implemented in 100 lines of bash.
|
|||||||
The following packages are needed to run bocker.
|
The following packages are needed to run bocker.
|
||||||
|
|
||||||
* btrfs-progs
|
* btrfs-progs
|
||||||
|
* curl
|
||||||
* iproute2
|
* iproute2
|
||||||
* iptables
|
* iptables
|
||||||
* util-linux >= 2.25.2
|
* util-linux >= 2.25.2
|
||||||
@ -34,30 +35,33 @@ Even if you meet the above prerequisites you probably still want to **run bocker
|
|||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
$ bocker init base-image/
|
$ bocker pull centos 7
|
||||||
Created: img_84632
|
######################################################################## 100.0%
|
||||||
|
######################################################################## 100.0%
|
||||||
|
######################################################################## 100.0%
|
||||||
|
Created: img_42150
|
||||||
|
|
||||||
$ bocker images
|
$ bocker images
|
||||||
IMAGE_ID
|
IMAGE_ID SOURCE
|
||||||
img_84632
|
img_42150 centos:7
|
||||||
|
|
||||||
$ bocker run img_84632 uname -sro
|
$ bocker run img_42150 cat /etc/centos-release
|
||||||
Linux 3.10.0-123.20.1.el7.x86_64 GNU/Linux
|
CentOS Linux release 7.1.1503 (Core)
|
||||||
|
|
||||||
$ bocker ps
|
$ bocker ps
|
||||||
CONTAINER_ID COMMAND
|
CONTAINER_ID COMMAND
|
||||||
ps_12277 uname -sro
|
ps_42045 cat /etc/centos-release
|
||||||
|
|
||||||
$ bocker logs ps_12277
|
$ bocker logs ps_42045
|
||||||
Linux 3.10.0-123.20.1.el7.x86_64 GNU/Linux
|
CentOS Linux release 7.1.1503 (Core)
|
||||||
|
|
||||||
$ bocker rm ps_12277
|
$ bocker rm ps_42045
|
||||||
Removed: ps_12277
|
Removed: ps_42045
|
||||||
|
|
||||||
$ bocker run img_84632 which wget
|
$ bocker run img_42150 which wget
|
||||||
which: no wget in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
|
which: no wget in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
|
||||||
|
|
||||||
$ bocker run img_84632 yum install -y wget
|
$ bocker run img_42150 yum install -y wget
|
||||||
Installing : wget-1.14-10.el7_0.1.x86_64 1/1
|
Installing : wget-1.14-10.el7_0.1.x86_64 1/1
|
||||||
Verifying : wget-1.14-10.el7_0.1.x86_64 1/1
|
Verifying : wget-1.14-10.el7_0.1.x86_64 1/1
|
||||||
Installed : wget.x86_64 0:1.14-10.el7_0.1
|
Installed : wget.x86_64 0:1.14-10.el7_0.1
|
||||||
@ -65,35 +69,25 @@ Complete!
|
|||||||
|
|
||||||
$ bocker ps
|
$ bocker ps
|
||||||
CONTAINER_ID COMMAND
|
CONTAINER_ID COMMAND
|
||||||
ps_14099 which wget
|
ps_42018 yum install -y wget
|
||||||
ps_43377 yum install -y wget
|
ps_42182 which wget
|
||||||
|
|
||||||
$bocker commit ps_43377 img_84632
|
$ bocker commit ps_42018 img_42150
|
||||||
Removed: img_84632
|
Removed: img_42150
|
||||||
Created: img_84632
|
Created: img_42150
|
||||||
|
|
||||||
$ bocker run img_84632 which wget
|
$ bocker run img_42150 which wget
|
||||||
/usr/bin/wget
|
/usr/bin/wget
|
||||||
|
|
||||||
$ bocker rm ps_14099
|
|
||||||
Removed: ps_14099
|
|
||||||
|
|
||||||
$ bocker rm ps_43377
|
|
||||||
Removed: ps_43377
|
|
||||||
|
|
||||||
$ bocker rm ps_95942
|
|
||||||
Removed: ps_95942
|
|
||||||
|
|
||||||
$ bocker rm img_84632
|
|
||||||
Removed: img_84632
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Functionality: Currently Implemented
|
## Functionality: Currently Implemented
|
||||||
|
|
||||||
* `docker build` †
|
* `docker build` †
|
||||||
|
* `docker pull`
|
||||||
* `docker images`
|
* `docker images`
|
||||||
* `docker ps`
|
* `docker ps`
|
||||||
* `docker run`
|
* `docker run`
|
||||||
|
* `docker exec`
|
||||||
* `docker logs`
|
* `docker logs`
|
||||||
* `docker commit`
|
* `docker commit`
|
||||||
* `docker rm` / `docker rmi`
|
* `docker rm` / `docker rmi`
|
||||||
@ -103,9 +97,10 @@ Removed: img_84632
|
|||||||
|
|
||||||
## Functionality: Not Yet Implemented
|
## Functionality: Not Yet Implemented
|
||||||
|
|
||||||
* Port Forwarding
|
|
||||||
* Data Volumes
|
|
||||||
* Data Volume Containers
|
* Data Volume Containers
|
||||||
|
* Data Volumes
|
||||||
|
* Port Forwarding
|
||||||
|
* Quota Support / CGroups
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
24
bocker
24
bocker
@ -4,26 +4,42 @@ btrfs_path='/var/bocker';
|
|||||||
function bocker_check() {
|
function bocker_check() {
|
||||||
btrfs subvolume list "$btrfs_path" | grep -qw "$1" && echo 0 || echo 1
|
btrfs subvolume list "$btrfs_path" | grep -qw "$1" && echo 0 || echo 1
|
||||||
}
|
}
|
||||||
function bocker_init() { #HELP Create an image:\nBOCKER init <image_directory>
|
function bocker_init() { #HELP Create an image from a directory:\nBOCKER init <directory>
|
||||||
uuid="img_$(shuf -i 42002-42254 -n 1)"
|
uuid="img_$(shuf -i 42002-42254 -n 1)"
|
||||||
if [[ -d "$1" ]]; then
|
if [[ -d "$1" ]]; then
|
||||||
[[ "$(bocker_check "$uuid")" == 0 ]] && bocker_run "$@"
|
[[ "$(bocker_check "$uuid")" == 0 ]] && bocker_run "$@"
|
||||||
btrfs subvolume create "$btrfs_path/$uuid" > /dev/null
|
btrfs subvolume create "$btrfs_path/$uuid" > /dev/null
|
||||||
cp -rf --reflink=auto "$1"/* "$btrfs_path/$uuid" > /dev/null
|
cp -rf --reflink=auto "$1"/* "$btrfs_path/$uuid" > /dev/null
|
||||||
|
[[ ! -f "$btrfs_path/$uuid"/img.source ]] && echo "$1" > "$btrfs_path/$uuid"/img.source
|
||||||
echo "Created: $uuid"
|
echo "Created: $uuid"
|
||||||
else
|
else
|
||||||
echo "No directory named '$1' exists"
|
echo "No directory named '$1' exists"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
function bocker_pull() { #HELP Pull an image from Docker Hub:\nBOCKER pull <name> <tag>
|
||||||
|
token="$(curl -sL -o /dev/null -D- -H 'X-Docker-Token: true' "https://index.docker.io/v1/repositories/$1/images" | tr -d '\r' | awk -F ': *' '$1 == "X-Docker-Token" { print $2 }')"
|
||||||
|
registry='https://registry-1.docker.io/v1'
|
||||||
|
id="$(curl -sL -H "Authorization: Token $token" "$registry/repositories/$1/tags/$2" | sed 's/"//g')"
|
||||||
|
[[ "${#id}" -ne 64 ]] && echo "No image named '$1:$2' exists" && exit 1
|
||||||
|
ancestry="$(curl -sL -H "Authorization: Token $token" "$registry/images/$id/ancestry")"
|
||||||
|
IFS=',' && ancestry=(${ancestry//[\[\] \"]/}) && unset IFS; tmp_uuid="$(uuidgen)" && mkdir /tmp/"$tmp_uuid"
|
||||||
|
for id in "${ancestry[@]}"; do
|
||||||
|
curl -#L -H "Authorization: Token $token" "$registry/images/$id/layer" -o /tmp/"$tmp_uuid"/layer.tar
|
||||||
|
tar xf /tmp/"$tmp_uuid"/layer.tar -C /tmp/"$tmp_uuid" && rm /tmp/"$tmp_uuid"/layer.tar
|
||||||
|
done
|
||||||
|
echo "$1:$2" > /tmp/"$tmp_uuid"/img.source
|
||||||
|
bocker_init /tmp/"$tmp_uuid" && rm -rf /tmp/"$tmp_uuid"
|
||||||
|
}
|
||||||
function bocker_rm() { #HELP Delete an image or container:\nBOCKER rm <image_id or container_id>
|
function bocker_rm() { #HELP Delete an image or container:\nBOCKER rm <image_id or container_id>
|
||||||
[[ "$(bocker_check "$1")" == 1 ]] && echo "No container named '$1' exists" && exit 1
|
[[ "$(bocker_check "$1")" == 1 ]] && echo "No container named '$1' exists" && exit 1
|
||||||
btrfs subvolume delete "$btrfs_path/$1" > /dev/null
|
btrfs subvolume delete "$btrfs_path/$1" > /dev/null
|
||||||
echo "Removed: $1"
|
echo "Removed: $1"
|
||||||
}
|
}
|
||||||
function bocker_images() { #HELP List images:\nBOCKER images
|
function bocker_images() { #HELP List images:\nBOCKER images
|
||||||
echo -e "IMAGE_ID"
|
echo -e "IMAGE_ID\t\tSOURCE"
|
||||||
for img in "$btrfs_path"/img_*; do
|
for img in "$btrfs_path"/img_*; do
|
||||||
basename "$img"
|
img=$(basename "$img")
|
||||||
|
echo -e "$img\t\t$(cat "$btrfs_path/$img/img.source")"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
function bocker_ps() { #HELP List containers:\nBOCKER ps
|
function bocker_ps() { #HELP List containers:\nBOCKER ps
|
||||||
@ -77,6 +93,6 @@ sed -n "s/^.*#HELP\\s//p;" < "$1" | sed "s/\\\\n/\n\t/g;s/$/\n/;s!BOCKER!${1/!/\
|
|||||||
}
|
}
|
||||||
[[ -z "${1-}" ]] && bocker_help "$0"
|
[[ -z "${1-}" ]] && bocker_help "$0"
|
||||||
case $1 in
|
case $1 in
|
||||||
init|rm|images|ps|run|exec|logs|commit) bocker_"$1" "${@:2}" ;;
|
pull|init|rm|images|ps|run|exec|logs|commit) bocker_"$1" "${@:2}" ;;
|
||||||
*) bocker_help "$0" ;;
|
*) bocker_help "$0" ;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -o errexit -o nounset -o pipefail
|
set -o errexit -o nounset -o pipefail
|
||||||
|
|
||||||
for img in $(./bocker images | grep 'img'); do
|
for img in $(./bocker images | grep 'img' | awk '{print $1}'); do
|
||||||
./bocker rm "$img"
|
./bocker rm "$img"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -o errexit -o nounset -o pipefail
|
set -o errexit -o nounset -o pipefail
|
||||||
|
|
||||||
[[ "$(./bocker images | head -n 1)" == 'IMAGE_ID' ]]
|
[[ "$(./bocker images | head -n 1)" == 'IMAGE_ID SOURCE' ]]
|
||||||
|
|||||||
16
tests/test_pull
Normal file
16
tests/test_pull
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -o errexit -o nounset -o pipefail
|
||||||
|
|
||||||
|
centos_img="$(./bocker pull centos 7 2> /dev/null | awk '{print $2}')"
|
||||||
|
./bocker run "$centos_img" cat /etc/redhat-release
|
||||||
|
ps="$(./bocker ps | grep 'cat /etc/redhat-release' | awk '{print $1}')"
|
||||||
|
logs="$(./bocker logs "$ps")"
|
||||||
|
./bocker rm "$ps"
|
||||||
|
[[ "$logs" == "CentOS Linux release 7"* ]]
|
||||||
|
|
||||||
|
ubuntu_img="$(./bocker pull ubuntu 14.04 2> /dev/null | awk '{print $2}')"
|
||||||
|
./bocker run "$ubuntu_img" tail -n1 /etc/lsb-release
|
||||||
|
ps="$(./bocker ps | grep 'tail -n1 /etc/lsb-release' | awk '{print $1}')"
|
||||||
|
logs="$(./bocker logs "$ps")"
|
||||||
|
./bocker rm "$ps"
|
||||||
|
[[ "$logs" == *"Ubuntu 14.04"* ]]
|
||||||
Loading…
x
Reference in New Issue
Block a user