# web2container4dev

> containerize web php projects; useful for development

Latest version **0.5.7** (published 2018-10-24) · WTFPL license · 0 weekly downloads

## Install

```sh
npm install web2container4dev
pnpm add web2container4dev
yarn add web2container4dev
bun add web2container4dev
```

Provides the command `web2container4dev`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.7 |
| Published | 2018-10-24 |
| First published | 2018-08-21 |
| Weekly downloads | 0 |
| License | WTFPL |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 22.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Alex Nevpryaga |
| Maintainers | santaklouse |

## Links

- npm: https://www.npmjs.com/package/web2container4dev
- Repository: https://github.com/santaklouse/web2container4dev
- Homepage: https://github.com/santaklouse/web2container4dev#readme
- Issues: https://github.com/santaklouse/web2container4dev/issues
- npm.io page: https://npm.io/package/web2container4dev

## Dependencies (6)

- [yargs](https://npm.io/package/yargs.md) ^12.0.1
- [hostile](https://npm.io/package/hostile.md) ^1.3.2
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.12.0
- [composefile](https://npm.io/package/composefile.md) ^0.3.0
- [npm-run-all](https://npm.io/package/npm-run-all.md) ^4.1.3
- [docker-compose](https://npm.io/package/docker-compose.md) ^0.8.1

## Recent versions

- 0.5.7 (latest) — 2018-10-24
- 0.5.6 — 2018-10-24
- 0.5.5 — 2018-10-23
- 0.5.4 — 2018-10-22
- 0.5.3 — 2018-10-22
- 0.5.2 — 2018-10-17
- 0.5.1 — 2018-10-17
- 0.5.0 — 2018-10-17
- 0.4.0 — 2018-10-17
- 0.3.5 — 2018-10-17
- 0.3.2 — 2018-10-17
- 0.3.1 — 2018-10-17
- 0.3.0 — 2018-10-16
- 0.2.0 — 2018-10-16
- 0.1.1 — 2018-09-12
- … 6 more at https://npm.io/package/web2container4dev/versions

## README

This project is for creating PHP / MySQL based applications from Docker Toolbox. (Available on Mac OS / Windows)
It would also support native Docker.

# Security notices

This template usually use for create development environment. We stil need some security checkup before deploy to production.

# Features

- PHP 5.5 / MySQL 5.6
- Bundled some PHP extensions needed for PHP based projects (tested on Laravel, Wordpress, Drupal)
- Supported locales for gettext (English / Swedish in first phase)
- Included wkhtmltopdf
- Included phpunit

# Get started

## Setup

 - !!!`install this package GLOBALLY`!!!!, and after that move to project folder and run:
 ```
 web2container4dev -c run --params='{"public-dir": "/public","php":"7"}'
 ```
----------------------||
----------------------||
------------------OLD README BELOW

- Clone this repository and rename root directory with your own one.
- Copy your app bootstrap code in `public` directory, eg. `public/index.php`. (You can replace hello world index.php)
- Other included / required files or libraries can store anywhere within project directory.

### Example cases:

- Drupal: Copy all files in `public` directory. For `drush` (Drupal Shell) it may be in root of project directory.
- Wordpress: Copy all files in `public` directory.
- Laravel: It can be project directory itself, we use existing `public/index.php` from Laravel already.
- Other things like composer.json, bower.json, Gruntfile.js, etc. can be in root of project directory since we may not need them access publicly.

## First run

- Install Docker Toolbox (or native Docker)
- Open `Docker Quickstart Terminal` (native Docker use normal bash)
- Run proxy container to handle virtual hosts:
```
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro --name nginx-proxy --restart always jwilder/nginx-proxy
```

Alternative way is using auto-proxy (build from golang, faster response) instead:
```
docker run -d -p 80:80 -p 443:443 -v /var/run/docker.sock:/var/run/docker.sock:ro --name auto-proxy --restart always ayufan/auto-proxy
```

- We also can use Traefik instead of nginx-proxy to gain more control reverse proxy
```
docker run -d -p 8080:8080 -p 80:80 \
-v /dev/null:/etc/traefik/traefik.toml \
-v /var/run/docker.sock:/var/run/docker.sock \
--name traefik \
--restart always \
traefik --web --docker --docker.domain=docker.dev --logLevel=DEBUG

```
In this case we should set labels in docker-compose.yml file instead of using ENV variable to set hostname:
```
...

web:
  labels:
    - "traefik.frontend.rule=Host:hostname.local"

...
```

- Run docker-compose to build up environment:
```
cd /path/to/web-project && docker-compose up -d
```
- To stop project containers:
```
cd /path/to/web-project && docker-compose stop
```
- Need to set file permission to 755 (executable) for bash script utilities:
```
chmod 755 ./web.sh ./scripts.sh ./db.sh
```

*Next time when we start project containers, use only docker-compose up -d command on project directory.*

## Virtual host access

We have two ways to tell web browser know local sitename created from Docker:

1. Use dnsmasq to generate all [domain].dev
2. Create manually in /etc/hosts file

### Setup dnsmasq from homebrew (Mac OS)

- This method need to install homebrew first `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`
- Then install dnsmasq from command: `brew install dnsmasq`
- ~~After brew installed, copy default config: `cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf`~~ *No need to copy sample for current version now*
- Edit conf: `vim /usr/local/etc/dnsmasq.conf`
  - Add a line:
`address=/dev/127.0.0.1`
OR 192.168.99.100 if you're using Docker Toolbox:
`address=/dev/192.168.99.100`
- Create resolver file for .dev
  - `sudo mkdir /etc/resolver`
  - Create dev file:
  ```
  sudo tee /etc/resolver/dev >/dev/null <<EOF  
  nameserver 127.0.0.1  
  EOF
  ```
- All config settled, start dnsmasq service and made it run on every start up: `sudo brew services start dnsmasq`
- To stop / start launchd service (e.g. reload config):
  - `sudo launchctl stop homebrew.mxcl.dnsmasq`
  - `sudo launchctl start homebrew.mxcl.dnsmasq`
- Test DNS: `dig something.dev @127.0.0.1`
- Add DNS 127.0.0.1 in `Network Preference > Advanced > DNS > +`

### Set hostname manually
Currently it can change virtual hostname from `sitename` to your own name in docker-compose.yml file separately for each projects.
Then you need to add entries in /etc/hosts manually. (C:\Windows\System32\drivers\etc\hosts on Windows)

For example, we have siteA, siteB & siteC projects:

```
192.168.99.100  siteA.local siteB.local siteC.local
```

## Database access

Call this command on project directory, it will open DB connection template on Sequel Pro (Mac OS) or MySQL Workbench (Windows)
```
./db.sh
```

## Run commands in containers

There are 2 bash scripts for terminal. `web.sh` (for web container) and `scripts.sh` (for one-time scripts container).

### Sample commands
```
./web.sh composer install
./web.sh php artisan list
./web.sh phpunit

./scripts.sh bower install
./scripts.sh grunt build
```

# Troubleshooting

- Conflict scripts container when rerun docker-compose up (because we ran it manually) -- just leave it or remove when we have updates for that container

```
Creating mysite_scripts_1

ERROR: Conflict. The name "/mysite_scripts_1" is already in use by container 356936e2baae4176776cc0db5b735f750e17654b7006f00a514bf0bd47faf121. You have to remove (or rename) that container to be able to reuse that name.
```

- Couldn't connect to Docker daemon sometimes on Mac OS X -- restart docker-machine then reset ENV on system from commands:

```
$ docker-machine restart default && eval $(docker-machine env default)
```

```
ERROR: Couldn't connect to Docker daemon - you might need to run `docker-machine start default`.
```

---
_Source: https://npm.io/package/web2container4dev · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
