Docker Shortie, simplifying calls to CLI commands inside docker containers.

Last update: Mar 31, 2022

What is DockTie

Is a simple wrapper script for commands inside docker container(s).

So for instance, what you would normally run as:

     docker-compose exec node node --v

becomes

     node --version

after tool is configured and initialized.

How to Use

  1. Clone the code from same parent directory as your project.
~$ pwd
/my/work/projects/

~$ git clone https://github.com/docktie/docktie.git
  1. Configure

Assuming your project is named cooltool, create corresponding _env file

~$ pwd
/my/work/projects/
~$ cd docktie
~$ cp conf/env.sample conf/cooltool_env ## change the variables accordingly.

NOTE: check conf/env.sample. Depending on your site structure, you may need to define RELATIVE_DOCKERCOMPOSE_DIR.

  1. And initialize:
~$ pwd
/my/work/projects/cooltool
~$ ../docktie/init.sh
NOTE: DockTie Dev Helper initialized.
      Utils(/my/work/projects/docktie/utils) prioritized in $PATH

(docktie > cooltool) ~$

You will get a visual indicator like "(docktie > cooltool)" in your CLI prompt once you successfully initialized.

NOTE: It has to be run from within your project. Otherwise, you will see this error:

~$ pwd
/my/work/projects/docktie
~$ ./init.sh
ERROR: 'init.sh' must be called from within project directory.

When you're done

Simply run the exit command:

(docktie > cooltool) ~$ exit
exit
DockTie Dev Helper exited.

~$

Utils Customization

Utils Structure

The utils are inside "utils/bin" directory.

Notice that in majority of utils, only docktie_cli (utils/docktie_cli) is actually calling the core (lib/kernel/core.bash.inc). This is because, only the script name matters.

~$ nl -ba utils/bin/docktie_cli
     1  #!/bin/bash
     2
     3  ## -------- source common library ---------
     4  PROJECT_ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )"
     5  . $PROJECT_ROOTDIR/etc/controller.bash.inc
     6
     7
     8  ## list of functions to auto-load
     9  autoload_functions "kernel/core"
    10
    11  ## ..............................
    12  ## main utility tool starts below
    13  ## ..............................
    14  core $(basename $0) $*

In line 3 above,

$(basename $0)

is the script name which works for symbolic links too. This makes maintenance easier and can be automated later.

Now on the utils kernel side lib/kernel/core.bash.inc, except for docktie_cli, a corresponding config is also expected and sourced/included. So utils/bin/artisan MUST have a corresponding etc/docktie/utils/artisan.conf.

Utils Example

For a concrete example, say you want to add a psql util located on postgres container/service.

All you have to do is:

  1. Add the symlink
~$ pwd
/my/work/projects/docktie/utils/bin
~$ ln -s docktie_cli postgres
~$
  1. And the kernel config file etc/docktie/postgres.conf with below contents:
docker_service_name='postgres'
command_within_service="psql"

Test and enjoy!

Limitation

Your project must be described in docker-compose format. Pure Dockerfile is not supported yet.

Pull Requests

Send in Pull Request(s) if you have ideas or saw bugs. Thanks in advance :)

Credits

As tool grows, so does its dependency hell. It was thus refactored for easier maintenance and followed the SHCF-way.

GitHub

https://github.com/docktie/docktie
Comments
  • 1. Add relative custom location of docker-compose.yml per project

    Up to this point, it is always assumed to be inside project directory https://github.com/icasimpan/docktie/blob/master/init.sh#L34

    export DOCKTIE_DOCKER_COMPOSE_FULLPATH="$(pwd)/docker-compose.yml"
    

    the "$(pwd)" part as it equates to where the docktie is initialized and is a known fact that it's always enforced from within the project dir:

    ## Enforce calling "init.sh" from within project directory.
    ##
    DOCKTIE_DIR=$(dirname $0)
    if [[ "$DOCKTIE_DIR" != "../docktie" ]]; then
        echo "ERROR: 'init.sh' must be called from within project directory."
        exit 1
    else
        DOCKTIE_DIR="$(dirname $(pwd))/docktie"
    fi
    

    Sometimes, projects will be in separate subfolders so this has to be catered. This should be named: RELATIVE_DOCKERCOMPOSE_DIR That should be defined in each project's conf/*_env file

    Reviewed by icasimpan at 2022-03-03 09:29
  • 2. docktie_cli getx improvement: exempt from initializing docktie

    Currently, docktie needs to be initialized before running any docktie-related commands.

    ~/work/docktie$ ./utils/bin/docktie_cli getx backup_db
    ERROR: DockTie needs to be initialized.
    

    Check if there's a way to exempt just docktie_cli getx since it's helpful specially when initial project setup.

    This is what's blocking it at the moment but that's an initial assessment. Need to check further:

    ~$ grep -iR "ERROR: DockTie needs to be initialized." *
    utils/lib/kernel/core.bash.inc:         echo 'ERROR: DockTie needs to be initialized.'
    
    Reviewed by casimpania at 2022-04-07 12:13
  • 3. Create docktie_cli

    docktie_cli - envisioned as the only command a user needs to remember. It should help out in every possible tool usage.

    Initial subcommands idea:

    • help - all available commands. Default when no commands given.
    • list - lists all utilities (within utils)
    • shell <service_name> - ssh to service name
    • services - list all the docker services

    Do after #1 is done

    Reviewed by casimpania at 2022-03-02 05:02
  • 4. Add 'env' subcommand to docktie_cli

    Idea is that it will show the exported environment variables that starts with DOCKTIE or PROJECT

    (docktie > cooltool) ~$ env|grep "^PROJECT\|^DOCKTIE"|sort
    

    where:

    • DOCKTIE - are for platform variables
    • PROJECT - except for $PROJECT_ROOTDIR, these are mostly defined in respective conf/*_env file.

    So, this would involve changes to init.sh as well to auto-detect all declared PROJECT_ (except for PROJECT_NAME). This is useful for things like shortcuts to BACKEND and FRONTEND or PARSER directories when working from command line.

    Parsing for env would be something like this:

    (docktie > cooltool) ~$ grep -v "^#\|^$\|^PROJECT_" env.sample
    DOCKER_CONTAINER_PREFIX=example
    AUTOSTART_PROJECT=0
    DOCKTIE_SERVICES_TO_START=""
    
    Reviewed by casimpania at 2022-05-06 02:56
  • 5. Incorporate db backup mechanism

    See how it's done in https://ismael.casimpan.com/quicktasks/docker-mysql-backup-to-local/.

    NOTE: In a version of docker-compose (1.26.2 or is it all of version 1?), cp command is not available and thus needs to downgrade to using the native docker cp.

    Reviewed by casimpania at 2022-03-30 13:37
  • 6. Add visual indicator to PS1 about project name

    Something like

    (docktie > cooltool) ~$
    

    Instead of just

    (docktie) ~$
    

    Relevant config to update is https://github.com/icasimpan/docktie/blob/master/conf/ps1_changer#L1

    Just add https://github.com/icasimpan/docktie/blob/master/conf/env.sample#L5 there.

    Reviewed by icasimpan at 2022-03-02 13:41
  • 7. Possible decoupling of services handled

    See how practical it is to decouple services from utils/core. Idea is, user only has to provide a service config file and core will simply detect all that's inside the services config directory.

    Maybe, move utils/core into utils/kernel/core and services config into utils/kernel/config.

    Reviewed by casimpania at 2022-03-02 01:36
  • 8. Remove dash or underscore from project directory name when detecting parameter for init.sh

    Docker removes dashes or underscore from project folder name and use it as default prefix.

    Example, if your project is "cool_project-uat", container prefix becomes coolprojectuat.

    Reviewed by casimpania at 2022-05-05 01:52
  • 9. Add option to allow running specific services during init

    When using some development environments like laradock, there are a lot of services that would be started if no specific ones are declared.

    Most of the time, you need only to run specific ones.

    Reviewed by casimpania at 2022-04-29 10:35
  • 10. Allow docktie to auto-up the project when explicitly told to do so

    The reason docktie needs the project to be manually up is that it doesn't want to dictate it. Developer still has the higher control on when to start/stop/down the docker project.

    BUT once the docker-compose environment is fully configured ../docktie/init.sh COULD auto-up the project.

    To give developer the choice to enable it or not, add a flag to the conf/*_env file, something like: AUTOSTART_PROJECT=1 Should be zero or commented out by default.

    Reviewed by icasimpan at 2022-03-31 15:32
  • 11. Create 'alias' for all commands done by docktie

    In some instances, docktie is overkill (e.g. in customer environments) but alias is very very light and would be helpful.

    Idea is to think of docktie as the source code for aliases and "compiling" would mean creating those alias that can be run in any environment including local. It is also quite fast as compared to raw docktie commands.

    Reviewed by casimpania at 2022-05-11 06:10
  • 12. Add feature for auto-switch user for certain containers defined in *_env file

    Sometimes, there's a need to switch user as containers mostly use root by default.

    Define in _env and make sure the following are included:

    • container name
    • use to switch to
    • if there's a need to define shell (for those users defined with /sbin/nologin, e.g. 'www-data')
    Reviewed by casimpania at 2022-05-05 02:35
  • 13. docktie_cli getx: improv to allow bulk/grouped extension to get

    Just like composer.lock where you have a lot of modules to install.

    Add it to something like a [getx] section of env file, one line per extension till a whitespace is found.

    This might help:

    • https://stackoverflow.com/questions/14676714/grep-match-all-characters-up-to-not-including-first-blank-space
    • https://stackoverflow.com/questions/7103531/how-to-get-the-part-of-a-file-after-the-first-line-that-matches-a-regular-expres
    Reviewed by casimpania at 2022-04-03 05:45
  • 14. devolve utils to docker-ext and only retain the core module (docktie_cli)

    CONS:

    • current symlinks to docktie_cli will now be a file (though still calling the docktie_cli way).

    PROS:

    • We can add an inline help at the top of each command
    • Developer may need to install a lot of extensions after but mitigated by #26

    NOTES:

    • Composer is still hardcoded within utils/lib/kernel/core.bash.inc. The rest are OK.
    Reviewed by casimpania at 2022-04-03 05:34
Demo of how you can run your Laravel app with Docker Compose. Look at docker-compose.yml and the docker folder. The rest is just a clean Laravel + Horizon install.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Oct 22, 2021
Quickly deploy a seedbox with self-hosted services and a web portal using Docker and docker-compose.
Quickly deploy a seedbox with self-hosted services and a web portal using Docker and docker-compose.

Seedbox Quickly deploy and configure a seedbox with self-hosted services and a web portal using Docker and a single docker-compose.yml file. Screensho

Jun 6, 2022
Brew PHP switcher is a simple shell script to switch your apache and CLI quickly between major versions of PHP
Brew PHP switcher is a simple shell script to switch your apache and CLI quickly between major versions of PHP

Brew PHP switcher is a simple shell script to switch your apache and CLI quickly between major versions of PHP. If you support multiple products/projects that are built using either brand new or old legacy PHP functionality. For users of Homebrew (or brew for short) currently only.

Jun 26, 2022
Full PHP development environment for Docker.
Full PHP development environment for Docker.

Full PHP development environment based on Docker. Use Docker First - Learn About It Later! Join Us Awesome People Laradock is an MIT-licensed open sou

Jun 24, 2022
A modern Docker LAMP stack and MEAN stack for local development
A modern Docker LAMP stack and MEAN stack for local development

The Devilbox Usage | Architecture | Community | Features | Intranet | Screenshots | Contributing | Logos | License Support for valid https out of the

Jun 26, 2022
Up and running with small Docker environments
Up and running with small Docker environments

Vessel Up and running with small Docker dev environments. Documentation Full documentation can be found at https://vessel.shippingdocker.com. Install

Jun 29, 2022
Symfony5 template w/ Docker config

Symfony5 w/ Docker config A project template in the following configuration: Symfony 5.2 PHP8 PostgreSQL 13.2 Separate Docker containers for Nginx, FP

May 14, 2022
Docker NAT容器自助部署php版本,实现从搭建到跑路的全生命周期功能。
Docker NAT容器自助部署php版本,实现从搭建到跑路的全生命周期功能。

DockerLabs-V1 游客可通过web页面直接创建出NAT容器,本项目从发布后将不再维护任何bug,以后有时间会出sdk重构版。 环境要求 使用了赛邮云发送短信号码,需要自己去申请appid和appkey填写到app_config.php文件中。需要修改所有html文件和api/kill.ph

Mar 4, 2022
The project provides a docker image for Files App(files.photo.gallery).
The project provides a docker image for Files App(files.photo.gallery).

For the purpose of learning,I replace the files.js with cracked version which just remove authorization code.

Apr 13, 2022
Multipurpose VIP Docker container images

VIP Container Images This repository is used to build Docker container images used, among others, by the VIP Local Development Environment. Images are

Mar 7, 2022
Laravel 5 with Dockerized Gulp, PHP-FPM, MySQL and nginx using docker-compose

docker-laravel Laravel 5 with Dockerized PHP-FPM, MySQL and nginx using docker-compose Usage Get Composer docker-compose run --rm phpnginx curl -O htt

Feb 8, 2022
Shopware 6 app boilerplate + Symfony backend + Dockware docker dev environment 💙

Shopware 6 app boilerplate with Symfony backend This boilerplate template can be used to get up and running with a docker-based dev setup for Shopware

Nov 14, 2021
Docker with PHP 7.4 fpm, Nginx, Composer, PhpUnit and MaridaDB

Clean Docker with PHP Docker with PHP 7.4 fpm, Nginx, Composer, PhpUnit and MariaDB Starting app docker-compose up -d Main page

Apr 26, 2022
Ponto de partida para utilização do Docker Compose 💙✨
Ponto de partida para utilização do Docker Compose 💙✨

Docker-compose Docker | WSL2 | PHP | Nginx | MySQL Esse projeto fornece um ponto de partida para integrar diferentes serviços usando um arquivo Compos

Nov 9, 2021
A package that allows you to generate simple and fast Docker configurations for your Laravel application!

A package that allows you to generate simple and fast Docker configurations for your Laravel application!

Dec 23, 2021
Docker-based workflow management system for Laravel

DevOption Workflows Workflows is a Docker-based workflow management system for Laravel applications. Installation You can install the package via comp

Jan 5, 2022
Runs a PHP-based startpage in Docker
Runs a PHP-based startpage in Docker

docker-php-startpage Runs a PHP-based startpage in Docker Source code: GitHub Docker container: Docker Hub Image base: PHP Init system: N/A Applicatio

Jun 4, 2022
Lamp Docker skeleton PHP + Nginx + Mysql + Redis

Stop installing the entire development stack on your local machine. This project will allow you to quickly start working with php. To install, you need to install docker locally.

Jun 25, 2022
ServD - a Docker PHP development environment heavily inspired by Laravel Valet and Laradock

ServD ServD is a Docker PHP development environment heavily inspired by Laravel Valet and Laradock, it supports multiple projects within a working dir

May 13, 2022