From c6907f708755151ad8502d71eb24bc736eb66688 Mon Sep 17 00:00:00 2001 From: Michael Strong Date: Mon, 22 May 2017 16:35:13 +1200 Subject: [PATCH] DOCS Add mount volume and port mapping examples --- docs/cookbook/container-run.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/cookbook/container-run.md b/docs/cookbook/container-run.md index bf42b409..7d6aa4a5 100644 --- a/docs/cookbook/container-run.md +++ b/docs/cookbook/container-run.md @@ -166,3 +166,37 @@ $containerConfig->setTty(true); ``` Be aware that there is no distinction between stdout and stderr in this mode. + + +## Mounting a Volume + +This example shows you can map your host volume `/home/myuser/myapp` to a container at `/app` + +```php +$containerConfig->setVolumes(['/home/myuser/myapp' => (object) []]); + +$hostConfig = new HostConfig(); +// hostpath:containerpath +$hostConfig->setBinds(['/home/myuser/myapp:/app']); + +$containerConfig->setHostConfig($hostConfig); +``` + +## Port Mapping + +This example shows how you can map port 8080 on your host machine to port 80 on the container. + +```php +$containerConfig->setTty(true); +$containerConfig->setExposedPorts(['80/tcp' => (object)[]]); + +$portBinding = new PortBinding(); +$portBinding->setHostPort('8080'); +$portBinding->setHostIp('0.0.0.0'); + +$portMap = new \ArrayObject(); +$portMap['80/tcp'] = [$portBinding]; + +$hostConfig = new HostConfig(); +$hostConfig->setPortBindings($portMap); +```