kba-team/dockertools 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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]

  • -h Display usage information.
  • -f <hosts-file> Use a different hosts file than /etc/hosts.
  • -r Only remove all the hostnames of containers created by docker-compose, but do not add them.

Examples:

  • vendor/bin/docker_hosts.sh: Remove and then add all docker containers in the /etc/hosts file.
  • vendor/bin/docker_hosts.sh -r: Just remove all docker containers from the /etc/hosts file.

Environment variables

  • DOCKER_REGISTRY Instead of using busybox:latest to manipulate the hosts file, ${DOCKER_REGISTRY}/busybox:latest will be used. This is useful, in case you manually cache docker images in a local registry for faster access.
  • BUSYBOX Instead of using busybox:latest to 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-hosts Add container hostnames and IPs to hosts file.
  • remove-hosts Remove container hostnames and IPs from hosts file.
  • exec Execute command(s) in docker container as ${DEFAULT_EXEC_USER:-www-data:www-data}. Available options:
    • -u | --user Run 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}
  • migrate Run the migrations command ${MIGRATE_COMMAND} inside the default container ${DEFAULT_CONTAINER:-web}.
  • seed Run the seed command ${MIGRATE_COMMAND} inside the default container ${DEFAULT_CONTAINER:-web}.
  • start Try to pull the current versions of the images, start the containers and add hostnames and IPs to the hosts file.
  • up Run start, migrate and seed commands.
  • stop Remove container hostnames and IPs from hosts file and stop the docker containers without destroying them.
  • down Remove container hostnames and IPs from hosts file and destroy the docker containers.
  • restart Run down and up commands.
  • cleanup Delete files owned by ${DEFAULT_EXEC_USER}. Available options:
    • --root Delete files owned by root.
  • behat Run behat tests. Any additional parameters will be added to the behat command.
  • phpunit Run phpunit tests. Any additional parameters will be added to the phpunit command.
  • help Show 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_USER The default user executing commands inside docker containers.
  • DEFAULT_CONTAINER The default container to execute commands in.
  • MIGRATE_COMMAND The command running the migrations to set up the DB structure. In case this variable is not defined, nothing happens.
  • SEED_COMMAND The command adding seed data to your empty DB. In case this variable is not defined, nothing happens.
  • PHPUNIT_BIN The path to the PHPunit binary. In case this variable is not defined, nothing happens.
  • BEHAT_BIN The 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 kba-team/dockertools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 17.06k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: Shell

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-04-03