Sign inSign up

jndev/docker-server

By jndev

•Updated over 8 years ago

Docker-server is a tool how to simple managed multiple web services with different hosts.

Image
0

332

jndev/docker-server repository overview

⁠DOCKER SERVER

Docker-server is a tool how to simple managed multiple web services with different hosts.

####Requirements

  • docker
  • docker-compose

For more information about docker or docker-compose visit official pages:

####Create docker-compose.yml

version: '3'
services:
  server:
    image: jndev/docker-server:alpine
    privileged: true
    volumes:
      - ./environments:/environments    #where will be store environment data
      - ./volumes:/volumes              #where will be store volumes data
    ports:
      - "80:80"
      - "443:443"

####Create dockerServer.sh handler script

#!/usr/bin/env bash
DOCKER_SERVER_CONFIG="/Users/jirka/work/composetest/docker-compose.yml" #set your location for docker-server docker-compose.yml

CMD=$1

echo ""
hash docker-compose &> /dev/null
if [ $? -eq 1 ]; then
	echo " DOCKER-SERVER (error):"
	echo " ========================"
	echo " FAIL: docker-compose not found!\n"
	exit;
fi

if [[ "$CMD" == "install" ]]; then

	echo " DOCKER-SERVER (install):"
	echo " ========================"

	docker-compose -f ${DOCKER_SERVER_CONFIG} up -d && \
	docker-compose -f ${DOCKER_SERVER_CONFIG} exec server docker-compose -f /docker-compose.yml up -d

	echo "\n SUCCESS: Ready to use. Try 'example' command.\n"

	exit;
fi

if [[ "$CMD" == "uninstall" ]]; then

	echo " DOCKER-SERVER (uninstall):"
	echo " =========================="

	docker-compose -f ${DOCKER_SERVER_CONFIG} down --volume

	echo "\n SUCCESS: Docker server was removed.\n"

	exit;
fi


if [[ "$CMD" == "stop" ]]; then

	echo " DOCKER-SERVER (stop):"
	echo " ====================="

	docker-compose -f ${DOCKER_SERVER_CONFIG} stop

	echo "\n SUCCESS: Docker server was stopped.\n"

	exit;
fi

if [[ "$CMD" == "start" ]]; then

	echo " DOCKER-SERVER (start):"
	echo " ======================"

	docker-compose -f ${DOCKER_SERVER_CONFIG} start

	echo "\n SUCCESS: Docker server was started.\n"

	exit;
fi

if [[ "$CMD" == "exec" ]]; then

	echo " DOCKER-SERVER (exec):"
	echo " ====================="

	if [[ "$2" == "" ]]; then
		echo " FAIL: Second params must be set. Example \"exec 'docker stats'\".\n"
		exit;
	fi

	docker-compose -f ${DOCKER_SERVER_CONFIG} exec server $2
	echo "\n\n"
	exit;
fi

if [[ "$CMD" == "example" ]]; then

	if [[ "$2" == "clean" ]]; then

		echo " DOCKER-SERVER (example clean):"
		echo " =============================="

		docker-compose -f ${DOCKER_SERVER_CONFIG} exec server docker rm -f example >/dev/null
		docker-compose -f ${DOCKER_SERVER_CONFIG} exec server docker rmi -f tutum/hello-world:latest >/dev/null

		echo "\n SUCCESS: Example was removed.\n"

		exit;
	fi


	echo " DOCKER-SERVER (example):"
	echo " ========================"

	docker-compose -f ${DOCKER_SERVER_CONFIG} exec server docker rm -f example >/dev/null
	docker-compose -f ${DOCKER_SERVER_CONFIG} exec server docker run --name example -d -e VIRTUAL_HOST=example.io --network=default_default tutum/hello-world:latest

	echo "\n SUCCESS: Visit example.io in browser. Maybe you need add line '127.0.0.1  example.io' into hosts. \n"

	exit;
fi


# HELP SECTION
echo " DOCKER-SERVER - help:"
echo " ====================="
echo " Syntax: dockerServer.sh <command>\n"
echo " Commands:"
echo "  - example                  Build an example image and run it on domain example.io"
echo "    example clean            Remove example build"
echo "  - exec '<cmd>'             Execute a command"
echo "  - help                     Show this help"
echo "  - install                  Install DOCKER-SERVER"
echo "  - start                    Star DOCKER-SERVER"
echo "  - stop                     Stop DOCKER-SERVER"
echo "  - uninstall                Uninstall DOCKER-SERVER"
echo "\n"



docker-compose up -d && \
docker-compose exec server docker-compose -f /docker-server/docker-compose.yml up -d 
⁠Create shortcut

Modify your .bash_profile nano ~/.bash_profile. Insert this line:

alias ds="sh <location-of-dockerServer.sh">

After that execute command for reload your bash profile file

source ~/.bash_profile

Thats it. Try in command line execute command ds

You should see somethink like this:

 DOCKER-SERVER - help:
 =====================
 Syntax: dockerServer.sh <command>

 Commands:
  - example                  Build an example image and run it on domain example.io
    example clean            Remove example build
  - exec '<cmd>'             Execute a command
  - help                     Show this help
  - install                  Install DOCKER-SERVER
  - start                    Star DOCKER-SERVER
  - stop                     Stop DOCKER-SERVER
  - uninstall                Uninstall DOCKER-SERVER

##TODO:

  • web application
    • for control deployment on server
    • for statistic purpose

Tag summary

Content type

Image

Digest

Size

125.7 MB

Last updated

over 8 years ago

docker pull jndev/docker-server:alpine3.7