Introduction {#sec
1. Introduction {#
The invention rela
Birth asphyxia: ex
/*----------------
Wendell Pierce Cas
Q:
Does the exist
The effects of the
Q:
What is the di
This book brings t#!/bin/bash
################################################################################
# This is the base script from which all the other Docker container creation scripts are based
# This is a template for base script use. If you are modifying this script in any way, please run:
# docker build -t docker_project . --file 'Dockerfile-base'
# to ensure that the Dockerfile has been updated
################################################################################
# If no args have been given, show usage and exit.
#
if [ "$#" -eq "0" ]; then
echo "Usage: ./build_script.sh [tag or sha1] [base image]"
echo "Example: ./build_script.sh 5f75ac18aa3d docker_project"
echo "Example: ./build_script.sh bd65d1bdc7ff 0e4b04afc9e4c7f1bacf2b9b9c4c3c1c82a3c0 1.0.0"
exit 1
fi
# Get the tag or sha1 for the current image
TAG=$(docker images -q --filter "reference=$1" | sed "s|.*/\(.*\)\..*|\1|")
# Find the latest tag or sha1 on the same major version, in case one was not provided
LATEST_TAG=$(echo "$TAG" | sed 's/docker\/.+\(.*\)\..*/\1/')
LATEST_SHA1=$(echo "$TAG" | sed 's/docker\/.+\(.*\)\..*/\2/')
# Tag is being provided as a tag. Check it is valid and increment if so.
if [ -z "$1" ]; then
TAG="$LATEST_TAG"
# Add some random characters so that incrementing fails on the next increment.
TAG="docker_project-$RANDOM-increment"
else
# Create a sha1 from the tag.
TAG="docker_project-$LATEST_TAG"
LATEST_SHA1="$LATEST_SHA1+increment"
fi
# Build a new container
docker build -t "$TAG" .
# Tag and push the image if you specified tags
if [ -n "$1" ]; then
# Create a sha1 from the tag.
TAG="docker_project-$LATEST_SHA1"
docker tag "$TAG" "$LATEST_TAG"
docker push "$LATEST_TAG"
# If you did not provide a reference, just use the local image.
# Otherwise, set the default Docker repository.
if [ -z "$1" ]; then
echo "docker.io/docker_project"
else
echo "$1"
fi
fi
A:
Your question title doesn't match the content of your question, so let me give a simple answer for the title's question.
You can do:
docker commit
in your case:
docker commit docker_project docker_project myimage
You need to replace myimage with the name of your repository.
You can now push this new image to your repository and will then be accessible through your docker repo.
Example:
docker.io/myuser/myimage-123
Note the -123 part.
Now you can simply do:
docker pull myuser/myimage-123:latest
to get the latest version and then change something and re-commit:
docker commit myuser/myimage-123:latest myuser/myimage-123:version2
If you want to avoid the whole "re-commit cycle", you can also tag the previous version and delete the source image:
docker tag myuser/myimage-123:latest myuser/myimage-123:version1
docker rmi myuser/myimage-123:version1
and then re-commit with only the "tag" that you like. You might also want to consider to add new configurations to your "tag" in order to be able to distinguish this new version from the older versions of your code. You can then always check your "tag" in order to upgrade it to the new version and avoid re-commiting your whole code-base.
A:
This is how I have finally accomplished my goal:
#! /bin/bash
################################################################################
# This is the base script from which all the other Docker container creation scripts are based
# This is a template for base script use. If you are modifying this script in any way, please run:
# docker build -t docker_project . --file 'Dockerfile-base'
# to ensure that the Dockerfile has been updated
################################################################################
# If no args have been given, show usage and exit.
#
if [ "$#" -eq "0" ]; then
echo "Usage: ./build_script.sh [tag or sha1] [base image]"
echo "Example: ./build_script.sh 5f75ac18aa3d docker_project"
echo "Example: ./build_script.sh bd65d1bdc7ff 0e4b04afc9e4c7f1bacf2b9b9c4c3c1c82a3c0 1.0.0"
exit 1
fi
# Get the tag or sha1 for the current image
TAG=$(docker images -q --filter "reference=$1" | sed "s|.*/\(.*\)\..*|\1|")
# Find the latest tag or sha1 on the same major version, in case one was not provided
LATEST_TAG=$(echo "$TAG" | sed 's/docker\/.+\(.*\)\..*/\1/')
LATEST_SHA1=$(echo "$TAG" | sed 's/docker\/.+\(.*\)\..*/\2/')
# Tag is being provided as a tag. Check it is valid and increment if so.
if [ -z "$1" ]; then
TAG="$LATEST_TAG"
# Add some random characters so that incrementing fails on the next increment.
TAG="docker_project-$RANDOM-increment"
docker rmi --force docker_project-$RANDOM-increment
TAG="docker_project-$LATEST_TAG"
else
# Create a sha1 from the tag.
TAG="docker_project-$LATEST_SHA1"
LATEST_SHA1="$LATEST_SHA1+increment"
fi
# Build a new container
docker build -t "$TAG" .
# Tag and push the image if you specified tags
if [ -n "$1" ]; then
# Create a sha1 from the tag.
TAG="docker_project-$LATEST_SHA1"
docker tag "$TAG" "$LATEST_TAG"
docker push "$LATEST_TAG"
# If you did not provide a reference, just use the local image.
# Otherwise, set the default Docker repository.
if [ -z "$1" ]; then
echo "docker.io/docker_project"
else
echo "$1"
fi
fi
Thank you for your help.