@@ -28,6 +28,18 @@ 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+
3143 .. doctest::
3244
3345 >>> from testcontainers.core.container import DockerContainer
@@ -41,18 +53,40 @@ def __init__(
4153 self ,
4254 image : str ,
4355 docker_client_kw : Optional [dict ] = None ,
56+ command : Optional [str ] = None ,
57+ env : Optional [dict [str , str ]] = None ,
58+ name : Optional [str ] = None ,
59+ ports : Optional [list [int ]] = None ,
60+ volumes : Optional [list [tuple [str , str , str ]]] = None ,
61+ network : Optional [Network ] = None ,
62+ network_aliases : Optional [list [str ]] = None ,
4463 ** kwargs ,
4564 ) -> None :
46- self .env = {}
65+ self .env = env or {}
66+
4767 self .ports = {}
68+ if ports :
69+ self .with_exposed_ports (* ports )
70+
4871 self .volumes = {}
72+ if volumes :
73+ for vol in volumes :
74+ self .with_volume_mapping (* vol )
75+
4976 self .image = image
5077 self ._docker = DockerClient (** (docker_client_kw or {}))
5178 self ._container = None
52- self ._command = None
53- self ._name = None
79+ self ._command = command
80+ self ._name = name
81+
5482 self ._network : Optional [Network ] = None
83+ if network is not None :
84+ self .with_network (network )
85+
5586 self ._network_aliases : Optional [list [str ]] = None
87+ if network_aliases :
88+ self .with_network_aliases (* network_aliases )
89+
5690 self ._kwargs = kwargs
5791
5892 def with_env (self , key : str , value : str ) -> Self :
0 commit comments