This Python script facilitates running a Docker container with specified resource limits and mounts the current working directory into the container. The container will be launched interactively with a Bash shell.
-
Arguments:
image_id: The ID of the Docker image to use (required).--container_name: Optional name for the container.--memory_limit: Memory limit for the container (default is2g).--cpu_limit: CPU limit for the container (default is4).
-
Docker Run Command:
- The script constructs and executes a
docker runcommand with the specified options. - The container is run interactively with the
-itoption and is removed after exit using the--rmoption. - The current directory is mounted into the container using the
-voption. - Memory and CPU limits are set with the
-mand--cpusoptions, respectively.
- The script constructs and executes a
Ensure you have the following installed:
- Python 3.x: Python Installation Guide
- Docker: Docker Installation Guide
Assuming that you`ve cloned this repo:
-
Run the following command to make sure that user can execute script:
sudo chmod u+x bear-docker-container
-
Place script in local binary directory:
sudo cp bear-docker-container /usr/local/bin/
-
You can now run the script at any time by typing:
bear-docker-container <image id>