mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-09-10 03:10:32 +00:00
27
projects/compose/image/Dockerfile
Normal file
27
projects/compose/image/Dockerfile
Normal file
@@ -0,0 +1,27 @@
|
||||
FROM docker/compose:1.13.0
|
||||
# because compose requires all sorts of dynamic libs, including glibc, it is much easier to
|
||||
# add docker client to compose than the reverse
|
||||
|
||||
ENV DOCKER_BUCKET get.docker.com
|
||||
ENV DOCKER_VERSION 17.05.0-ce
|
||||
ENV DOCKER_SHA256 340e0b5a009ba70e1b644136b94d13824db0aeb52e09071410f35a95d94316d9
|
||||
|
||||
# we need docker compose and docker load
|
||||
# also need curl to test availability of docker API
|
||||
RUN apk add --update curl
|
||||
|
||||
# we only need the client
|
||||
RUN set -x \
|
||||
&& curl -fSL "https://${DOCKER_BUCKET}/builds/Linux/x86_64/docker-${DOCKER_VERSION}.tgz" -o docker.tgz \
|
||||
&& echo "${DOCKER_SHA256} *docker.tgz" | sha256sum -c - \
|
||||
&& tar -xzvf docker.tgz \
|
||||
&& mv docker/docker /usr/bin/ \
|
||||
&& rm -rf docker docker.tgz \
|
||||
&& docker -v
|
||||
|
||||
|
||||
RUN mkdir -p /compose /app
|
||||
WORKDIR /app
|
||||
COPY . /app
|
||||
ENTRYPOINT ["/app/waitfordocker.sh"]
|
||||
CMD ["/app/load-images-and-compose.sh"]
|
17
projects/compose/image/load-images-and-compose.sh
Executable file
17
projects/compose/image/load-images-and-compose.sh
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
#########
|
||||
#
|
||||
# load any cached mounted images, and run compose
|
||||
#
|
||||
########
|
||||
|
||||
[ -n "$DEBUG" ] && set -x
|
||||
|
||||
for image in /compose/images/*.tar ; do
|
||||
docker image load -i $image && rm -f $image
|
||||
done
|
||||
|
||||
|
||||
docker-compose -f /compose/docker-compose.yml up -d
|
47
projects/compose/image/waitfordocker.sh
Executable file
47
projects/compose/image/waitfordocker.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
#########
|
||||
#
|
||||
# wait for docker socket to be ready, then run the rest of the command
|
||||
#
|
||||
########
|
||||
RETRIES=${RETRIES:-"-1"}
|
||||
WAIT=${WAIT:=10}
|
||||
[ -n "$DEBUG" ] && set -x
|
||||
|
||||
# keep retrying until docker is ready or we hit our limut
|
||||
retry_or_fail() {
|
||||
local retry_count=0
|
||||
local success=1
|
||||
local cmd=$1
|
||||
local retryMax=$2
|
||||
local retrySleep=$3
|
||||
local message=$4
|
||||
until [[ $retry_count -ge $retryMax && $retryMax -ne -1 ]]; do
|
||||
echo "trying to $message"
|
||||
set +e
|
||||
$cmd
|
||||
success=$?
|
||||
set -e
|
||||
[[ $success == 0 ]] && break
|
||||
retry_count=$(( $retry_count+1 )) || true
|
||||
echo "attempt number $retry_count failed to $message, sleeping $retrySleep seconds..."
|
||||
sleep $retrySleep
|
||||
done
|
||||
# did we succeed?
|
||||
if [[ $success != 0 ]]; then
|
||||
echo "failed to $message after $retryMax tries. Exiting..." >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
connect_to_docker() {
|
||||
[ -S /var/run/docker.sock ] || return 1
|
||||
curl --unix-socket /var/run/docker.sock http://localhost/containers/json >/dev/null 2>&1 || return 1
|
||||
}
|
||||
# try to connect to docker
|
||||
retry_or_fail connect_to_docker $RETRIES $WAIT "connect to docker"
|
||||
|
||||
# if we got here, we succeeded
|
||||
$@
|
Reference in New Issue
Block a user