# Dockerize

When assuming the use of container in our workflow we come to face some challenges. Soon we realize that it is complicated to have a complete environment without installing any tool on the host.

[Tevun's Dockerize](https://github.com/tevun/dockerize) initiative seeks to deliver a comfortable workflow for those who use Docker in their day-to-day lives.

Using it you will abstract all the services you use to develop to run with docker.

## How to configure

{% hint style="danger" %}
Read the steps before you run them to understand what is being done. We will modify your bash environment and we don't want cause problems to you = )
{% endhint %}

### Getting started

To use *`dockerize`* you can clone or download de zip of project from Github.

#### Create a clone

Create with your terminal an easy-to-find folder

```bash
mkdir -p ~/.config/tevun
```

Make a local project clone

```bash
git clone git@github.com:tevun/dockerize.git ~/.config/tevun/dockerize
```

OR

#### Download

Download the zip of this project

```bash
wget -O ~/.config/tevun/dockerize.zip https://codeload.github.com/tevun/dockerize/zip/master
```

Then unzip the contents of the zip

```bash
unzip dockerize.zip && mv dockerize-master dockerize
```

## Configuration

To use *`dockerize`* you need add the [bashrc](https://github.com/tevun/dockerize/blob/master/.bashrc) script to your terminal environment.

{% code title="\~/.bashrc" %}

```bash
...
source ~/.config/tevun/dockerize/.bashrc # or your custom path
...
```

{% endcode %}

If you are using the project for the first time you can use our convenient configuration script to add local documents to your terminal environment.

To do this, run the configuration script

```bash
bash ~/.config/tevun/dockerize/configure.sh # or your custom path
```

### How to use `Dockerize`

After add the script to terminal will be created a command engine to toggle service commands to run on "[global images](https://github.com/tevun/dockerize/tree/master/dockerize/environment)" and/or containers relative to the project of the folder it is in.

We currently have the following configured services:

* artisan
* composer
* node
* npm
* php
* phpunit
* quasar
* vue
* yarn
* react

In other words, you can simply execute:

```bash
php -v
```

To perform the service php in your docker host.

### Smart behavior

*`Dockerize`* tries to detect which container should be run for each service. When you are in a folder that does not have a container associated with it, your output will be global.

![](https://2469683102-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LcGdxC_-iro75-ypwyF%2F-LcXWX8OJ2SUBFdimhhA%2F-LcXdrDJoXgSeShk4vpj%2Fimage.png?alt=media\&token=0e5c0960-8164-41ba-8b7e-b6bfe3341a24)

When the current directory is associated with one container the output will be different.

![](https://2469683102-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LcGdxC_-iro75-ypwyF%2F-LcXWX8OJ2SUBFdimhhA%2F-LcXdhwosRadS2_vQf2O%2Fimage.png?alt=media\&token=fb921046-efee-458c-bad6-359347979bc0)

### Detection strategies

* global suffix: *`Dockerize`* will first attempt to find a container that has the folder name and suffix associated with the service. You can check the service suffix in the property `T_DOCKERIZE_SERVICE` of file `dockerize/environment/variables.ini.sample`. If your project folder is `foo` and `T_DOCKERIZE_SERVICE` is `app` the name of your service must be `foo-app` to this detection match.&#x20;
* service suffix: The second try is check if there is a container with the folder name followed by an hyphen and the name of service. If your project folder is `acme` and you create a service with name `acme-node` you can perform the command `node` and *`dockerize`* will use this container.
* file `.dockerize`: You create a file called `.dockerize` in your project folder and describe the name of containers of services.

## Customizing

You can customize the main project settings. Go to the environment folder and evaluate the parameters that are defined there.

```bash
cd ~/.config/tevun/dockerize/environment
```

## Common Problems

* **Address already in use:**&#x20;
  * **message**: docker: Error response from daemon: driver failed programming external connectivity on endpoint \* (): Error starting userland proxy: listen tcp 0.0.0.0:: bind: address already in use.
  * **solution**: use the guidelines in the Customizing section and configure the ports in the images.ini file according to your port usage.
