Skip to content

Latest commit

 

History

History

README.org

Here you can find some scripts and utilities to use when using our baseimages.

docker-stop

This script sends the SIGPWR signal to /sbin/init inside the container, triggering the shutdown process and allowing the running services to cleanly shutdown.

docker-stop <container-id> [<container-id>...]

docker-ssh

This script helps using ssh to log into a running container by setting some default options and looking up the container ip from the container name.

docker-ssh [ssh options] <user>@<container-id> [command]

When using our baseimages, the default ssh private key is ${HOME}/.ssh/bitergia-docker. To use another identity, add the -i parameter with the desired key.

docker-ssh [ssh options] -i /path/to/my/private-key <user>@<container-id> [command]

docker-scp

This script helps using scp to transfer files from/to a running container with a running ssh daemon.

docker-scp [scp options] <user>@<container-id>:path/to/remote/files path/to/local/files
docker-scp [scp options] path/to/local/files <user>@<container-id>:path/to/remote/files

get-container-ip

Helper script to obtain the IP address of a running container.

get-container-ip <container-id>

get-docker-hosts

Helper script to add the running containers to /etc/hosts or update the existing info. The script will add any alias generated via docker links and try to preserve any other alias that may already exist on the file for the same container name.

$ ./get-docker-hosts -h
Usage: ./get-docker-hosts [options]

  -h  --help                 Show this help.
  -v  --version              Show program version.

  Optional parameters:

  -m  --modify-hosts         Modify the system /etc/hosts file (requires root permission)
  -f  --hosts-file <file>    Specify the hosts file to modify (defaults to /etc/hosts)

Default behaviour is to dump to stdout the lines to add.

### BEGIN Docker container IPs ###
172.17.0.7    compose_chanchanapp_1
172.17.0.6    compose_idas_1 idas idas_1
172.17.0.5    compose_cygnus_1 cygnus cygnus_1
172.17.0.4    compose_idmauthlegacy_1 idmauthlegacy idmauthlegacy_1
172.17.0.3    compose_orion_1 orion orion_1
172.17.0.2    compose_mongodb_1 mongodb mongodb_1
### END Docker container IPs ###

Use the –hosts-file parameter to specify another file instead of /etc/hosts (i.e. for testing).

To modify the /etc/hosts file you must use the –modify-hosts parameter and have root permission (i.e. via sudo). The script will try to make a backup copy of the file prior to modifying it, cancelling the operation if the copy fails.

entrypoint-common.sh

This script contains some common functions used on the docker-entrypoint.sh scripts of our containers.

To use this functions, add the following line to the docker-entrypoint.sh script:

source /entrypoint-common.sh

And import the file into the docker image by adding this line to the Dockerfile:

ADD https://raw.githubusercontent.com/Bitergia/docker/master/utils/entrypoint-common.sh /

Available functions

check_host_port <host> <port> [max-tries]

Checks that <port> on <host> is open. If no <max-tries> is specified, it uses the value specified by DEFAULT_MAX_TRIES environment variable.

This function uses nc (netcat) to do the check, waiting 1 second between each consecutive retry.

You can use this function to wait for a <port> on <host> to be open before doing something else.

check_url <url> <regex> [max-tries]

Checks that the data returned from <url> matches <regex>. If no <max-tries> is specified, it uses the value specified by DEFAULT_MAX_TRIES environment variable.

This function uses curl to retrieve the <url>, waiting 1 second between each consecutive retry.

You can use this funcion to wait for a web server to be ready by checking the data returned for a specific <url> contains <regex>.

check_var <variable> [default-value]

Checks that <variable> is defined. If no <default-value> is specified and <variable> is undefined, it fails. If <default-value> is specified and <variable> is undefined, it defines <variable> with <default-value>. If <variable> is defined, it leaves it untouched.

You can use this function to check for specific variables to be defined and assign default values to them.

check_file <file> [max-tries]

Checks that <file> exists and has read permission. If no <max-tries> is specified, it uses the value specified by DEFAULT_MAX_TRIES environment variable.

You can use this function to wait for the existance of a <file> and that it is readable.

Available variables

DEFAULT_MAX_TRIES

Defines the default maximum number of tries for the previous functions. Default value is 60.