@@ -28,6 +28,20 @@ class DockerContainer:
2828 """
2929 Basic container object to spin up Docker instances.
3030
31+ Args:
32+ image: The name of the image to start.
33+ docker_client_kw: Dictionary with arguments that will be passed to the
34+ docker.DockerClient init.
35+ command: Optional execution command for the container.
36+ name: Optional name for the container.
37+ ports: Ports to be exposed by the container. The port number will be
38+ automatically assigned on the host, use
39+ :code:`get_exposed_port(PORT)` method to get the port number on the host.
40+ volumes: Volumes to mount into the container. Each entry should be a tuple with
41+ three values: host path, container path and. mode (default 'ro').
42+ network: Optional network to connect the container to.
43+ network_aliases: Optional list of aliases for the container in the network.
44+
3145 .. doctest::
3246
3347 >>> from testcontainers.core.container import DockerContainer
@@ -41,18 +55,40 @@ def __init__(
4155 self ,
4256 image : str ,
4357 docker_client_kw : Optional [dict ] = None ,
58+ command : Optional [str ] = None ,
59+ env : Optional [dict [str , str ]] = None ,
60+ name : Optional [str ] = None ,
61+ ports : Optional [list [int ]] = None ,
62+ volumes : Optional [list [tuple [str , str , str ]]] = None ,
63+ network : Optional [Network ] = None ,
64+ network_aliases : Optional [list [str ]] = None ,
4465 ** kwargs ,
4566 ) -> None :
46- self .env = {}
67+ self .env = env or {}
68+
4769 self .ports = {}
70+ if ports :
71+ self .with_exposed_ports (* ports )
72+
4873 self .volumes = {}
74+ if volumes :
75+ for vol in volumes :
76+ self .with_volume_mapping (* vol )
77+
4978 self .image = image
5079 self ._docker = DockerClient (** (docker_client_kw or {}))
5180 self ._container = None
52- self ._command = None
53- self ._name = None
81+ self ._command = command
82+ self ._name = name
83+
5484 self ._network : Optional [Network ] = None
85+ if network is not None :
86+ self .with_network (network )
87+
5588 self ._network_aliases : Optional [list [str ]] = None
89+ if network_aliases :
90+ self .with_network_aliases (* network_aliases )
91+
5692 self ._kwargs = kwargs
5793
5894 def with_env (self , key : str , value : str ) -> Self :
0 commit comments