Creates a container. Parameters are similar to those for the ``docker run`` command except it doesn't support the attach options (``-a``). The arguments that are passed directly to this function are host-independent configuration options. Host-specific configuration
(self, image, command=None, hostname=None, user=None,
detach=False, stdin_open=False, tty=False, ports=None,
environment=None, volumes=None,
network_disabled=False, name=None, entrypoint=None,
working_dir=None, domainname=None, host_config=None,
mac_address=None, labels=None, stop_signal=None,
networking_config=None, healthcheck=None,
stop_timeout=None, runtime=None,
use_config_proxy=True, platform=None)
| 219 | return res |
| 220 | |
| 221 | def create_container(self, image, command=None, hostname=None, user=None, |
| 222 | detach=False, stdin_open=False, tty=False, ports=None, |
| 223 | environment=None, volumes=None, |
| 224 | network_disabled=False, name=None, entrypoint=None, |
| 225 | working_dir=None, domainname=None, host_config=None, |
| 226 | mac_address=None, labels=None, stop_signal=None, |
| 227 | networking_config=None, healthcheck=None, |
| 228 | stop_timeout=None, runtime=None, |
| 229 | use_config_proxy=True, platform=None): |
| 230 | """ |
| 231 | Creates a container. Parameters are similar to those for the ``docker |
| 232 | run`` command except it doesn't support the attach options (``-a``). |
| 233 | |
| 234 | The arguments that are passed directly to this function are |
| 235 | host-independent configuration options. Host-specific configuration |
| 236 | is passed with the `host_config` argument. You'll normally want to |
| 237 | use this method in combination with the :py:meth:`create_host_config` |
| 238 | method to generate ``host_config``. |
| 239 | |
| 240 | **Port bindings** |
| 241 | |
| 242 | Port binding is done in two parts: first, provide a list of ports to |
| 243 | open inside the container with the ``ports`` parameter, then declare |
| 244 | bindings with the ``host_config`` parameter. For example: |
| 245 | |
| 246 | .. code-block:: python |
| 247 | |
| 248 | container_id = client.api.create_container( |
| 249 | 'busybox', 'ls', ports=[1111, 2222], |
| 250 | host_config=client.api.create_host_config(port_bindings={ |
| 251 | 1111: 4567, |
| 252 | 2222: None |
| 253 | }) |
| 254 | ) |
| 255 | |
| 256 | |
| 257 | You can limit the host address on which the port will be exposed like |
| 258 | such: |
| 259 | |
| 260 | .. code-block:: python |
| 261 | |
| 262 | client.api.create_host_config( |
| 263 | port_bindings={1111: ('127.0.0.1', 4567)} |
| 264 | ) |
| 265 | |
| 266 | Or without host port assignment: |
| 267 | |
| 268 | .. code-block:: python |
| 269 | |
| 270 | client.api.create_host_config(port_bindings={1111: ('127.0.0.1',)}) |
| 271 | |
| 272 | If you wish to use UDP instead of TCP (default), you need to declare |
| 273 | ports as such in both the config and host config: |
| 274 | |
| 275 | .. code-block:: python |
| 276 | |
| 277 | container_id = client.api.create_container( |
| 278 | 'busybox', 'ls', ports=[(1111, 'udp'), 2222], |