Skip to content

Commit 7250891

Browse files
micmania1joelwurtz
authored andcommitted
DOCS Add mount volume and port mapping examples (docker-php#245)
1 parent 97baa5f commit 7250891

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

docs/cookbook/container-run.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,37 @@ $containerConfig->setTty(true);
166166
```
167167

168168
Be aware that there is no distinction between stdout and stderr in this mode.
169+
170+
171+
## Mounting a Volume
172+
173+
This example shows you can map your host volume `/home/myuser/myapp` to a container at `/app`
174+
175+
```php
176+
$containerConfig->setVolumes(['/home/myuser/myapp' => (object) []]);
177+
178+
$hostConfig = new HostConfig();
179+
// hostpath:containerpath
180+
$hostConfig->setBinds(['/home/myuser/myapp:/app']);
181+
182+
$containerConfig->setHostConfig($hostConfig);
183+
```
184+
185+
## Port Mapping
186+
187+
This example shows how you can map port 8080 on your host machine to port 80 on the container.
188+
189+
```php
190+
$containerConfig->setTty(true);
191+
$containerConfig->setExposedPorts(['80/tcp' => (object)[]]);
192+
193+
$portBinding = new PortBinding();
194+
$portBinding->setHostPort('8080');
195+
$portBinding->setHostIp('0.0.0.0');
196+
197+
$portMap = new \ArrayObject();
198+
$portMap['80/tcp'] = [$portBinding];
199+
200+
$hostConfig = new HostConfig();
201+
$hostConfig->setPortBindings($portMap);
202+
```

0 commit comments

Comments
 (0)