kba-team/dockertools
Composer 安装命令:
composer require kba-team/dockertools
包简介
Scripts to remove and add all running docker containers in your /etc/hosts file.
README 文档
README
docker-compose is a very useful tool, especially if you're programming inside a network of docker-containers. Accessing the (TCP) services of these docker containers, however is not so easy. To the best of my knowledge there are currently no tools available, that will add the IPs and hostnames of your running network to your hosts /etc/hosts file- until now.
Why not use <insert DNS/discovery service here>?
Running a DNS service for docker containers always messes with the DNS settings of your workstation. Especially if these DNS/discovery services themselves run inside docker containers on an active development workstation. Resolving DNS issues is not an easy task. Contrary to that the /etc/hosts file is simple. It couldn't care less if your workstation switches domains, DNS services, VPNs, etc. on-the-fly. In case something goes wrong, you can always edit the file manually. It was made for adding the hosts of a docker network (joke). I like the /etc/hosts file (not a joke).
Add to your PHP project
composer require kba-team/dockertools --dev
Add entries to hosts
In a bridged docker network, remove and add the IP addresses and hostnames of containers created by docker-compose in the /etc/hosts file. This will save you the hassle of port-forwarding, name resolvers, etc.
The script first removes all existing entries of all the hostnames of containers created by docker-compose in the /etc/hosts file and then adds them. This ensures, that there a no duplicate entries in the /etc/hosts file.
It is implied, that this script can only be called while docker containers are running.
Usage: docker_hosts.sh [-h] [-f <hosts-file>] [-r]
-hDisplay usage information.-f <hosts-file>Use a different hosts file than/etc/hosts.-rOnly remove all the hostnames of containers created bydocker-compose, but do not add them.
Examples:
vendor/bin/docker_hosts.sh: Remove and then add all docker containers in the/etc/hostsfile.vendor/bin/docker_hosts.sh -r: Just remove all docker containers from the/etc/hostsfile.
Environment variables
DOCKER_REGISTRYInstead of usingbusybox:latestto manipulate the hosts file,${DOCKER_REGISTRY}/busybox:latestwill be used. This is useful, in case you manually cache docker images in a local registry for faster access.BUSYBOXInstead of usingbusybox:latestto manipulate the hosts file, use the docker image from the variable. This is useful, in case you manually cache docker images in a local registry for faster access or if you want to use a different busybox version.
Automate docker-compose
In order to automate commands that need execution after docker-compose did its work, use bin/docker.sh.
Usage: vendor/bin/docker.sh <command>
Available commands are:
add-hostsAdd container hostnames and IPs to hosts file.remove-hostsRemove container hostnames and IPs from hosts file.execExecute command(s) in docker container as${DEFAULT_EXEC_USER:-www-data:www-data}. Available options:-u|--userRun commands using user ID$(id -u)and group ID$(id -g).-c|--container <name>Run commands in the specified container. Default container:${DEFAULT_CONTAINER:-web}
migrateRun the migrations command${MIGRATE_COMMAND}inside the default container${DEFAULT_CONTAINER:-web}.seedRun the seed command${MIGRATE_COMMAND}inside the default container${DEFAULT_CONTAINER:-web}.startTry to pull the current versions of the images, start the containers and add hostnames and IPs to the hosts file.upRun start, migrate and seed commands.stopRemove container hostnames and IPs from hosts file and stop the docker containers without destroying them.downRemove container hostnames and IPs from hosts file and destroy the docker containers.restartRun down and up commands.cleanupDelete files owned by${DEFAULT_EXEC_USER}. Available options:--rootDelete files owned byroot.
behatRun behat tests. Any additional parameters will be added to the behat command.phpunitRun phpunit tests. Any additional parameters will be added to the phpunit command.helpShow help.
Environment variables
Configure the environment variables in your .env file. That way it can be used by docker-compose as well (DRY).
DEFAULT_EXEC_USERThe default user executing commands inside docker containers.DEFAULT_CONTAINERThe default container to execute commands in.MIGRATE_COMMANDThe command running the migrations to set up the DB structure. In case this variable is not defined, nothing happens.SEED_COMMANDThe command adding seed data to your empty DB. In case this variable is not defined, nothing happens.PHPUNIT_BINThe path to the PHPunit binary. In case this variable is not defined, nothing happens.BEHAT_BINThe path to the Behat binary. In case this variable is not defined, nothing happens.
kba-team/dockertools 适用场景与选型建议
kba-team/dockertools 是一款 基于 Shell 开发的 Composer 扩展包,目前已累计 17.06k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 04 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 kba-team/dockertools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kba-team/dockertools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 17.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-04-03