PHPackages                             kba-team/dockertools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. kba-team/dockertools

ActiveTools[DevOps &amp; Deployment](/categories/devops)

kba-team/dockertools
====================

Scripts to remove and add all running docker containers in your /etc/hosts file.

v4.1.4(4mo ago)117.1k↓75.9%[3 issues](https://github.com/the-kbA-team/dockertools/issues)MITShellCI passing

Since Apr 3Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/the-kbA-team/dockertools)[ Packagist](https://packagist.org/packages/kba-team/dockertools)[ RSS](/packages/kba-team-dockertools/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)DependenciesVersions (13)Used By (0)

Docker tools
============

[](#docker-tools)

[docker-compose](https://docs.docker.com/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 &lt;insert DNS/discovery service here&gt;?
------------------------------------------------------

[](#why-not-use-insert-dnsdiscovery-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
-----------------------

[](#add-to-your-php-project)

```
composer require kba-team/dockertools --dev
```

Add entries to hosts
--------------------

[](#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 ] [-r]`

- `-h` Display usage information.
- `-f ` 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:

[](#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

[](#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
-----------------------

[](#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 `

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 ` 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

[](#environment-variables-1)

Configure the environment variables in your `.env` file. That way it can be used by docker-compose as well ([DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)).

- `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.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance56

Moderate activity, may be stable

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~288 days

Recently: every ~374 days

Total

11

Last Release

129d ago

Major Versions

2.0.1 → 3.0.02021-12-22

3.0.1 → 4.0.02022-01-11

2.0.2 → v4.1.22024-03-25

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1704466?v=4)[Greg](/maintainers/grej)[@grej](https://github.com/grej)

![](https://www.gravatar.com/avatar/4d7106acf139a0e8ec30679a6b3e44be2bc4a40dec1611821ce32b7b0da5d420?d=identicon)[tigerduck](/maintainers/tigerduck)

---

Top Contributors

[![gregor-j](https://avatars.githubusercontent.com/u/17705875?v=4)](https://github.com/gregor-j "gregor-j (31 commits)")

---

Tags

container-managementdockerdocker-ip-addresshostsfile

### Embed Badge

![Health badge](/badges/kba-team-dockertools/health.svg)

```
[![Health](https://phpackages.com/badges/kba-team-dockertools/health.svg)](https://phpackages.com/packages/kba-team-dockertools)
```

###  Alternatives

[widop/google-analytics-bundle

Google certificate-based authentication in server-to-server interactions with google analytics

43283.2k](/packages/widop-google-analytics-bundle)[in2code/in2publish_core

Content publishing extension to connect stage and production server

40143.4k](/packages/in2code-in2publish-core)[tiamo/phpas2

PHPAS2 is a php-based implementation of the EDIINT AS2 standard

4778.9k](/packages/tiamo-phpas2)[wapmorgan/php-rpm-packager

RPM packager for PHP applications.

106.6k](/packages/wapmorgan-php-rpm-packager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
