Compare commits

..

3 Commits

Author SHA1 Message Date
mrkmntal
a43de98578 Refactor Option 13: Streamline bash script to Docker image conversion workflow 2025-11-01 20:00:21 -04:00
6087426e08 Merge branch 'main' of https://mentalnet.xyz/gitea/markmental/tuxdock
Merging dockerfile update into gitea updated code
2025-10-28 17:14:40 -04:00
e056c1d6a1 Added support for converting bash scripts to Dockerfiles 2025-10-28 17:09:37 -04:00
4 changed files with 76 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ It offers a clean, interactive menu for common Docker operations like pulling im
- 🔹 **Interactive container management** — start, stop, remove, or attach to containers with simple numbered menus.
- 🔹 **Port mapping made clear** — automatically prompts for and explains host ↔ container port bindings.
- 🔹 **Image operations** — pull, list, and delete Docker images.
- 🔹 **Script-to-image workflow** — turn a bash setup script into a Dockerfile and build the resulting image in one go.
- 🔹 **Quick MySQL setup** — spin up a MySQL container with version, password, and port configuration in seconds.
- 🔹 **Get container IP address** — cleanly retrieves and displays only the containers assigned IP.
- 🔹 **Modern C++ design** — built with classes, minimal dependencies, and clear abstractions.
@@ -59,7 +60,8 @@ Tux-Dock: Docker Management Menu
10. Attach Shell to Running Container
11. Spin Up MySQL Container
12. Get Container IP Address
13. Exit
13. Create Dockerfile & Build Image from Bash Script
14. Exit
```
Each action guides you through the required steps.

View File

@@ -4,6 +4,8 @@
#include <cstdlib>
#include <sstream>
#include <array>
#include <fstream>
#include <filesystem>
using namespace std;
@@ -19,6 +21,7 @@ public:
void stopContainer();
void removeContainer();
void execShell();
void createDockerfile();
void spinUpMySQL();
void showContainerIP();
@@ -193,6 +196,66 @@ void DockerManager::showContainerIP() {
cout << "Container IP Address: " << ip;
}
void DockerManager::createDockerfile() {
string baseImage, bashScriptPath, outputFile, imageName;
cout << "Enter base Docker image (e.g., ubuntu:22.04): ";
cin >> baseImage;
cout << "Enter path to bash script to convert (e.g., setup.sh): ";
cin >> bashScriptPath;
if (!filesystem::exists(bashScriptPath)) {
cout << "Error: Bash script not found.\n";
return;
}
cout << "Enter output Dockerfile name (e.g., Dockerfile or Dockerfile_app): ";
cin >> outputFile;
if (outputFile.empty()) outputFile = "Dockerfile";
ifstream scriptFile(bashScriptPath);
ofstream dockerfile(outputFile);
if (!scriptFile.is_open() || !dockerfile.is_open()) {
cout << "Error: Unable to open file(s).\n";
return;
}
// Write Dockerfile header
dockerfile << "FROM " << baseImage << "\n";
dockerfile << "WORKDIR /app\n\n";
dockerfile << "# Auto-generated by Tux-Dock\n";
string line;
while (getline(scriptFile, line)) {
if (line.empty()) continue;
// Skip comments or shebang
if (line.rfind("#", 0) == 0 || line.rfind("#!", 0) == 0)
continue;
dockerfile << "RUN " << line << "\n";
}
dockerfile << "\nCMD [\"/bin/bash\"]\n";
dockerfile.close();
scriptFile.close();
cout << "Dockerfile created successfully: " << outputFile << "\n";
cout << "Enter image name to build from this Dockerfile (e.g., myimage): ";
cin >> imageName;
if (imageName.empty()) {
cout << "No image name provided. Skipping build.\n";
return;
}
cout << "Building Docker image '" << imageName << "'...\n";
runCommand("docker build -t " + imageName + " -f " + outputFile + " .");
cout << "Docker build command executed.\n";
}
// ---------------- Menu ----------------
int main() {
@@ -214,7 +277,8 @@ int main() {
<< "10. Attach Shell to Running Container\n"
<< "11. Spin Up MySQL Container\n"
<< "12. Get Container IP Address\n"
<< "13. Exit\n"
<< "13. Create Dockerfile & Build Image from Bash Script\n"
<< "14. Exit\n"
<< "----------------------------------\n"
<< "Choose an option: ";
@@ -233,7 +297,8 @@ int main() {
case 10: docker.execShell(); break;
case 11: docker.spinUpMySQL(); break;
case 12: docker.showContainerIP(); break;
case 13:
case 13: docker.createDockerfile(); break;
case 14:
cout << "Exiting Tux-Dock.\n";
return 0;
default:
@@ -241,4 +306,3 @@ int main() {
}
}
}

6
option13_script.sh Normal file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
echo "Setting up application directory"
mkdir -p /app/bin
echo '#!/bin/bash' > /app/bin/run.sh
echo 'echo "Hello from Tux-Dock generated image"' >> /app/bin/run.sh
chmod +x /app/bin/run.sh

BIN
tux-dock Executable file

Binary file not shown.