Created
February 3, 2016 18:47
-
-
Save lruslan/3dea3b3d52a66531b2a1 to your computer and use it in GitHub Desktop.
Dockerfile stored in image matedata
This file contains 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
#!/bin/bash | |
# Author: Ruslan Lutsenko 2016-02-03 | |
# Build docker image with Dockerfile being stored as image metadata using labels | |
#check necessary utils | |
which jq|| { echo "Error: missing jq"; exit 1; } | |
which base64|| { echo "Error: missing base64"; exit 1; } | |
#example Dockerfile with LABEL being set | |
cat << EOF > Dockerfile | |
FROM ubuntu:14.04 | |
ARG base64_dockerfile="" | |
LABEL dockerfile=\$base64_dockerfile | |
EOF | |
#encode Dockerfile in Base64 so it safe to pass it as a label | |
base64_dockerfile=$(cat Dockerfile |base64 -w0) | |
# build image with dockerfile content being passed as an argument | |
docker build --rm -t my_image_with_dockerfile_in_metadata -f Dockerfile --build-arg base64_dockerfile=${base64_dockerfile} . | |
#remove temporary dockerfile | |
rm Dockerfile | |
echo "Dockerfile extracted from image metadata:" | |
docker inspect -f "{{json .Config.Labels }}" my_image_with_dockerfile_in_metadata| jq -r .dockerfile| base64 -d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment