cli
1. Help
Command: bin/cli --help
SYNOPSIS:
Easy connection to docker container.
USAGE: cli [OPTIONS] [ARGUMENTS]
USAGE: cli [--help|-h] [--config]
[--bash-framework-config <bash-framework-config>] [--verbose|-v] [-vv] [-vvv]
[--log-level <log-level>] [--log-file <log-file>]
[--display-level <display-level>] [--no-color] [--theme <theme>] [--version]
[--quiet|-q]
ARGUMENTS:
[container {single}] Container should be the name of a profile from profile list,
check containers list below.
If no value provided, it will load the container
specified in default configuration.
Default: project-apache2
[user {single}] user to connect on this container
If no value provided, it will load the user
specified in default configuration.
Default: www-data
[command {single}] The command to execute
If no value provided, it will load the command
specified in default configuration.
Default: /bin/bash
GLOBAL OPTIONS:
--help, -h {single}
Displays this command help
--config {single}
Displays configuration
--bash-framework-config <bash-framework-config> {single}
Use alternate bash framework configuration.
--verbose, -v {single}
Info level verbose mode (alias of --display-level INFO)
-vv {single}
Debug level verbose mode (alias of --display-level DEBUG)
-vvv {single}
Trace level verbose mode (alias of --display-level TRACE)
--log-level <log-level> {single}
Set log level
Possible values:
- OFF
- ERR
- ERROR
- WARN
- WARNING
- INFO
- DEBUG
- TRACE
Default value: OFF
--log-file <log-file> {single}
Set log file
Default value: /logs/bash.log
--display-level <display-level> {single}
Set display level
Possible values:
- OFF
- ERR
- ERROR
- WARN
- WARNING
- INFO
- DEBUG
- TRACE
Default value: INFO
--no-color {single}
Produce monochrome output. alias of --theme noColor.
--theme <theme> {single}
Choose color theme - default-force means colors will be produced even if
command is piped.
Possible values:
- default
- default-force
- noColor
Default value: default
--version {single}
Print version information and quit.
--quiet, -q {single}
Quiet mode, doesn't display any output.
DESCRIPTION:
AVAILABLE PROFILES (from /bash/conf/cliProfiles)
This list can be overridden in /home/www-data/.bash-tools/cliProfiles
- default
- mysql
- mysql.remote
- node
- redis
- web
AVAILABLE CONTAINERS:
EXAMPLES:
to connect to mysql container in bash mode with user mysql
cli mysql-container-name mysql '/bin/bash'
to connect to web container with user root
cli web root
CREATE NEW PROFILE:
You can create new profiles in /home/www-data/.bash-tools/cliProfiles.
This script will be called with the
arguments userArg, containerArg, commandArg
The script has to compute the following
variables finalUserArg, finalContainerArg, finalCommandArg
VERSION: 3.0
AUTHOR: [François Chastanet](https://github.com/fchastanet)
SOURCE FILE: https://github.com/fchastanet/bash-tools-framework/tree/master/src/_binaries/Docker/cli/cli-binary.yaml
LICENSE: MIT License
Copyright (c) 2020-now François Chastanet
2. Example 1: open bash on a container named web
cli web
will actually execute this command :
MSYS_NO_PATHCONV=1 MSYS2_ARG_CONV_EXCL='\*'
docker exec -it -e COLUMNS="$(tput cols)" -e LINES="$(tput lines)" --user=
apache2 //bin/bash
3. Example 2: connect to mysql container with root user
cli mysql root bash
will actually execute this command :
MSYS_NO_PATHCONV=1 MSYS2_ARG_CONV_EXCL='\*'
docker exec -e COLUMNS="$(tput cols)" -e LINES="$(tput lines)" -it --user=root
project-mysql bash
4. Example 3: connect to mysql server in order to execute a query
will actually execute this command :
MSYS_NO_PATHCONV=1 MSYS2_ARG_CONV_EXCL='\*'
docker exec -it -e COLUMNS="$(tput cols)" -e LINES="$(tput lines)" --user=mysql
project-mysql //bin/bash -c 'mysql -h127.0.0.1 -uroot -proot -P3306'
5. Example 4: pipe sql command to mysql container
echo 'SELECT
table_schema AS "Database",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.TABLES' | bin/cli mysql
will actually execute this command :
MSYS_NO_PATHCONV=1 MSYS2_ARG_CONV_EXCL='\*'
docker exec -i -e COLUMNS="$(tput cols)" -e LINES="$(tput lines)" --user=mysql
project-mysql //bin/bash -c 'mysql -h127.0.0.1 -uroot -proot -P3306'
notice that as input is given to the command, tty option is not provided to docker exec
Or, if you want, you can alternatively use the GitHub discussion Q&A for feedback and questions.