This Bash script streamlines the management of Docker containers by providing functionalities for starting, stopping, and removing containers.
- Docker installed on your system.
-
Make the script executable:
chmod +x docker_container_manager.sh
-
Run the script with the following parameters:
./docker_container_manager.sh CONTAINER_NAME DOCKER_IMAGE [HOST_PORT] [CONTAINER_PORT]
CONTAINER_NAME
: Name for the Docker container.DOCKER_IMAGE
: Docker image to use.HOST_PORT
(Optional): Port on the host machine (default: 8080).CONTAINER_PORT
(Optional): Port within the Docker container (default: 80).
-
Start Container:
The script checks if the specified Docker container is already running. If not, it starts the container with the provided parameters.
-
Remove Container:
After starting the container, the script asks if you want to remove the container. If confirmed, it removes the container.
-
Stop Container:
If you choose not to remove the container, the script asks if you want to stop the container. If confirmed, it stops the running container.
-
The script uses Docker commands, so ensure Docker is installed and accessible in your system environment.
-
User interactions are prompted for confirmation, providing flexibility and control over container management.
-
Feel free to customize the script according to your specific needs.