You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
ASYD/ASYD_Docker/docker-03/myweb_v1/build.sh

34 lines
1.1 KiB

#!/bin/bash
# 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 myweb:v1
# 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 myweb:v1
# tell user what to do :)
echo "fire up browser and type 'http://$(hostname).simple.eee.intern:8080/' into address bar"
read -n 1 -p "when done, press any key to stop (and remove) the webserver container."
echo "stopping container $CNTR and cleaning up, hang on...."
docker stop $CNTR
echo "done. bye then :)"