docker_wrapper API Documentation
DockerImage
Class providing the necessary interface to interact with a Docker image and create containers.
Source code in src/docker_wrapper/docker_helpers.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
image_hash: str
property
Return the full hash of the image
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Hash value. |
image_tag: str
property
Return the tag of the image
If the image has an explicit numeric version return that, else return the first 10 characters of the image hash.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Return string to be used at the image tag. |
image_url: str
property
Return the full image URL, that is the
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
String result |
tagged_name: str
property
Return the tuple
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
String result |
__init__(docker_registry_prefix='', **kwargs)
Initialize the DockerImage object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docker_registry_prefix |
str
|
The prefix of the Docker registry URL. Defaults to "". |
''
|
**kwargs |
int
|
Additional keyword arguments. |
{}
|
Source code in src/docker_wrapper/docker_helpers.py
21 22 23 24 25 26 27 28 29 30 31 32 33 | |
build_image(force_build=False)
Build the Docker image if a specific version does not already exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force_build |
bool
|
Iff True then build the image regardless . Defaults to False. |
False
|
Source code in src/docker_wrapper/docker_helpers.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
folder_hash(docker_path)
staticmethod
Compute the hash of the docker image based on the contents of the Docker folder of the project
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
docker_path |
str
|
Path of the Docker folder that contains the Dockerfile the entrypoint and any other related logic. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Return the hash of the contents of the Docker folder. |
Source code in src/docker_wrapper/docker_helpers.py
45 46 47 48 49 50 51 52 53 54 55 56 57 | |
get_docker_run_args()
Return the list of additional arguments to pass to the docker run command
This function should be overridden by the child classes to provide the necessary arguments.
Source code in src/docker_wrapper/docker_helpers.py
143 144 145 146 147 148 149 | |
image_exists(url)
Return true if a docker image exists locally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url |
str
|
Full URL:TAG name of the image |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True iff the image exists locally |
Source code in src/docker_wrapper/docker_helpers.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
pull()
Pull the image from the registry.
Source code in src/docker_wrapper/docker_helpers.py
118 119 120 121 | |
push()
Push the image to the registry
Source code in src/docker_wrapper/docker_helpers.py
123 124 125 126 | |
run(project_dir, prompt=False, mount_home=False, cmds=None, network=None, privileged=False, enable_gui=False, ports=None, volumes=None, envs=None, enable_sudo=False, mount_host_passwd=True)
Run a container from the Docker Image
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_dir |
Path
|
Project we want to work inside the container. Mount the volume inside the container |
required |
prompt |
bool
|
Iff true start the container in interactive mode and start a prompt to provide to the user. Defaults to False. |
False
|
cmds |
Optional[List[str]]
|
List of commands to run inside the container. Defaults to None. |
None
|
network |
Optional[str]
|
Name of the network to connect the container to. Defaults to None. |
None
|
privileged |
bool
|
Enable privileged mode. Defaults to False. |
False
|
enable_gui |
bool
|
Enable support for starting GUI apps inside the container. Defaults to False. |
False
|
ports |
Optional[List[str]]
|
List of ports to enable to open from the container. Defaults to None. |
None
|
volumes |
Optional[List[str]]
|
List of volumes to mount inside the container. |
None
|
enable_sudo |
bool
|
Enable sudo inside the container. Defaults to False. This option mounts the sudoers file inside the container. |
False
|
mount_host_passwd |
bool
|
Mount the host passwd related files inside the
container and make use of the |
True
|
Source code in src/docker_wrapper/docker_helpers.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
Command line interface of the Docker Wrapper module
LoggingLevel
Bases: str, Enum
Enum holding the different logging argument values.
Attributes:
| Name | Type | Description |
|---|---|---|
CRITICAL |
str
|
Represents the 'CRITICAL' logging level. |
ERROR |
str
|
Represents the 'ERROR' logging level. |
WARNING |
str
|
Represents the 'WARNING' logging level. |
INFO |
str
|
Represents the 'INFO' logging level. |
DEBUG |
str
|
Represents the 'DEBUG' logging level. |
Source code in src/docker_wrapper/cli.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
__create_image(image_name, **kwargs)
Instantiate an DockerImage object (or its subclass) for the specified Image
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_name |
str
|
Name of the image to create an image for. |
required |
**kwargs |
Dict[str, str]
|
Additional arguments to pass to the DockerImage object. |
{}
|
Raises:
| Type | Description |
|---|---|
Exit
|
Failure if the image is not found |
Returns:
| Type | Description |
|---|---|
DockerImage
|
docker_helpers.DockerImage: Docker image object to be used to interact with it. |
Source code in src/docker_wrapper/cli.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
__get_image_name_value(image_name)
Get the string value of image_name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_name |
Union[str, EnumClassType]
|
Value returned by the CLI |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Actual value |
Source code in src/docker_wrapper/cli.py
133 134 135 136 137 138 139 140 141 142 143 144 | |
create_cli(image_dir=None, env_config_arg=None)
Create the command line interface of the Docker Wrapper
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_dir |
Optional[str]
|
Directory where the Docker image Dockerfiles and related code are located. Defaults to None. |
None
|
env_config_arg |
Optional[Dict[str, str]]
|
Configuration environment of the repository. Dictionary containing environment configuration values. |
None
|
Returns:
| Type | Description |
|---|---|
Typer
|
typer.Typer: Typer class wit the registered command line arguments. See the main() |
Typer
|
function how an object can be instantiated. |
Source code in src/docker_wrapper/cli.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | |
find_extensions(image_dir)
Find all available Docker images and extension modules that enable working with them
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_dir |
Path
|
Path containing the docker images. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Type[DockerImage]]
|
Dict[str, Callable[[], docker_helpers.DockerImage]]: Dictionary of docker image names and |
Dict[str, Type[DockerImage]]
|
object constructors we can call. |
Source code in src/docker_wrapper/cli.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
get_env_config()
Get the configuration of the repository
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dict[str, str]: Configuration of the repository |
Source code in src/docker_wrapper/cli.py
61 62 63 64 65 66 67 | |
main()
Helper main function
Source code in src/docker_wrapper/cli.py
359 360 361 362 | |
set_env_config(config)
Set the configuration of the repository
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config |
Dict[str, str]
|
Configuration of the repository |
required |
Source code in src/docker_wrapper/cli.py
51 52 53 54 55 56 57 58 | |