#!/bin/bash # use the base of the current working directory as the new image name (e.g., "webimg:v1") IMAGE_NAME=$(basename $(pwd)):v1 # creates an image "myweb:v1" by commiting a container. # start with "./build.sh" in current directory # create a random container name and use throuout this scrip CNTR=$(date | md5sum | head -c 10) echo "working with container name '$CNTR'" if [ "$(docker ps -q -f name=$CNTR)" ]; then echo "container '$CNTR' exists, exiting"; exit 1; fi # create nginx-container named web docker run -it --rm -d -p 8080:80 --name $CNTR nginx # copy static webpage into container docker cp index.html $CNTR:/usr/share/nginx/html/ # commit running container to image docker commit $CNTR $IMAGE_NAME # stop container (which will also delete the container because of --rm ) docker stop $CNTR # start new container from image myweb:v1 and expose port 80 to 8080 on host docker run -it --rm -d -p 8080:80 --name $CNTR $IMAGE_NAME # tell user what to do :) echo "fire up browser and type 'http://$(hostname).simple.eee.intern:8080/' into address bar" echo "you should see our webpage" echo read -n 1 -p "when done, press any key to stop (and remove) the webserver container." echo echo "stopping container $CNTR and cleaning up, hang on...." docker stop $CNTR echo "done. bye then"