Last active
December 2, 2024 18:50
-
-
Save thanoojgithub/547459765084fec0f927d321d43e6071 to your computer and use it in GitHub Desktop.
pull and execute ubuntu container using docker compose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
ubuntu-container: | |
image: ubuntu:latest | |
container_name: ubuntu_container | |
tty: true | |
stdin_open: true | |
volumes: | |
- ./data:/data # Optional: Mount a local directory to the container | |
ports: | |
- "22:22" # Optional: Map SSH port if needed (or other services) | |
environment: | |
- TZ=IST # Set the timezone (optional) | |
command: ["sleep","infinity"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
apt update -y && apt upgrade -y | |
apt install -y curl | |
curl --version | |
apt install -y vim | |
vim --version | |
echo "use 'vi start-deps.sh'" | |
apt install -y openjdk-21-jdk | |
javac -version | |
java -version | |
apt install -y git | |
git -v | |
apt install -y unzip | |
apt install -y wget | |
wget -N https://services.gradle.org/distributions/gradle-8.11.1-bin.zip | |
mkdir /opt/gradle | |
unzip -d /opt/gradle gradle-8.11.1-bin.zip | |
ls /opt/gradle/gradle-8.11.1 | |
BASE_PATH=$PATH | |
echo $PATH | |
echo $BASE_PATH | |
export PATH=$PATH:/opt/gradle/gradle-8.11.1/bin | |
echo $PATH | |
gradle -v | |
cd ~ | |
mkdir codebase | |
cd codebase | |
git clone https://github.com/thanoojgithub/SpringDataREST.git | |
cd SpringDataREST/ | |
ls -ltr | |
gradle clean build | |
echo "Running Spring Boot DATA REST Application" | |
#gradle bootRun | |
nohup gradle bootRun > application.log 2>&1 & | |
echo $! > save_pid.txt | |
cat save_pid.txt | |
sleep 10 | |
cat application.log | |
[ -f /root/codebase/SpringDataREST/build/reports/problems/problems-report.html ] && cat /root/codebase/SpringDataREST/build/reports/problems/problems-report.html | |
curl -X GET http://localhost:8080/actuator/health | |
curl -X GET http://localhost:8080/api/customers | |
curl -X POST http://localhost:8080/actuator/shutdown | |
echo "killing Spring Boot DATA REST Application" | |
kill -9 `cat save_pid.txt` | |
gradle --status | |
gradle --stop | |
gradle --status | |
rm save_pid.txt | |
rm application.log | |
cd .. | |
ls -ltr | |
rm -rf SpringDataREST | |
cd .. | |
ls -ltr | |
rm -rf codebase | |
rm -rf /opt/gradle | |
cd ~ | |
#ls -ltr | |
#rm gradle-8.11.1-bin.zip | |
[ -f /root/codebase/SpringDataREST/build/reports/problems/problems-report.html ] && rm /root/codebase/SpringDataREST/build/reports/problems/problems-report.html | |
ls -ltr | |
export PATH=$BASE_PATH | |
echo $PATH |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prerequisite: | |
1. install chocolatey on Windows OS | |
https://chocolatey.org/install | |
then, do a windows restart | |
2. install docker-desktop | |
choco install docker-desktop | |
then, do a windows restart | |
PS C:\Users\Admin> docker version | |
Client: | |
Version: 27.3.1 | |
API version: 1.47 | |
Go version: go1.22.7 | |
Git commit: ce12230 | |
Built: Fri Sep 20 11:42:27 2024 | |
OS/Arch: windows/amd64 | |
Context: desktop-linux | |
Server: Docker Desktop 4.36.0 (175267) | |
Engine: | |
Version: 27.3.1 | |
API version: 1.47 (minimum version 1.24) | |
Go version: go1.22.7 | |
Git commit: 41ca978 | |
Built: Fri Sep 20 11:41:11 2024 | |
OS/Arch: linux/amd64 | |
Experimental: false | |
containerd: | |
Version: 1.7.21 | |
GitCommit: 472731909fa34bd7bc9c087e4c27943f9835f111 | |
runc: | |
Version: 1.1.13 | |
GitCommit: v1.1.13-0-g58aa920 | |
docker-init: | |
Version: 0.19.0 | |
GitCommit: de40ad0 | |
PS C:\Users\Admin> docker compose version | |
Docker Compose version v2.30.3-desktop.1 | |
PS C:\Users\Admin> | |
now, we are ready to run ubuntu container using docker compose | |
PS C:\Users\Admin> cat .\docker-compose.yml | |
services: | |
ubuntu-container: | |
image: ubuntu:latest | |
container_name: ubuntu_container | |
tty: true | |
stdin_open: true | |
volumes: | |
- ./data:/data # Optional: Mount a local directory to the container | |
ports: | |
- "22:22" # Optional: Map SSH port if needed (or other services) | |
environment: | |
- TZ=IST # Set the timezone (optional) | |
command: ["sleep","infinity"] | |
PS C:\Users\Admin> docker-compose up -d | |
[+] Running 2/2 | |
✔ Network admin_default Created 0.0s | |
✔ Container ubuntu_container Started 0.5s | |
PS C:\Users\Admin> docker images | |
REPOSITORY TAG IMAGE ID CREATED SIZE | |
ubuntu latest fec8bfd95b54 6 weeks ago 78.1MB | |
PS C:\Users\Admin> docker ps | |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
756afa3365f2 ubuntu:latest "sleep infinity" 10 minutes ago Up 10 minutes 0.0.0.0:22->22/tcp ubuntu_container | |
PS C:\Users\Admin> docker container exec -ti ubuntu_container bash | |
root@756afa3365f2:/# | |
here you can use two options: | |
1. run start-deps.sh file | |
sh start-deps.sh | |
2. Follow step-by-step process | |
root@756afa3365f2:/# apt update | |
root@756afa3365f2:/# apt upgrade | |
root@756afa3365f2:/# apt install vim | |
root@756afa3365f2:/# apt install openjdk-21-jdk | |
root@756afa3365f2:/# javac -version | |
javac 21.0.5 | |
root@756afa3365f2:/# java -version | |
openjdk version "21.0.5" 2024-10-15 | |
OpenJDK Runtime Environment (build 21.0.5+11-Ubuntu-1ubuntu124.04) | |
OpenJDK 64-Bit Server VM (build 21.0.5+11-Ubuntu-1ubuntu124.04, mixed mode, sharing) | |
root@756afa3365f2:/# apt install git | |
root@756afa3365f2:/# git -v | |
git version 2.43.0 | |
root@756afa3365f2:/# apt install unzip | |
root@756afa3365f2:/# apt install wget | |
root@756afa3365f2:/# wget https://services.gradle.org/distributions/gradle-8.11.1-bin.zip | |
root@756afa3365f2:/# mkdir /opt/gradle | |
root@756afa3365f2:/# unzip -d /opt/gradle gradle-8.11.1-bin.zip | |
export PATH=$PATH:/opt/gradle/gradle-8.11.1/bin | |
root@756afa3365f2:/# gradle -v | |
openjdk version "21.0.5" 2024-10-15 | |
OpenJDK Runtime Environment (build 21.0.5+11-Ubuntu-1ubuntu124.04) | |
OpenJDK 64-Bit Server VM (build 21.0.5+11-Ubuntu-1ubuntu124.04, mixed mode, sharing) | |
------------------------------------------------------------ | |
Gradle 4.4.1 | |
------------------------------------------------------------ | |
Build time: 2012-12-21 00:00:00 UTC | |
Revision: none | |
Groovy: 2.4.21 | |
Ant: Apache Ant(TM) version 1.10.14 compiled on September 25 2023 | |
JVM: 21.0.5 (Ubuntu 21.0.5+11-Ubuntu-1ubuntu124.04) | |
OS: Linux 5.15.146.1-microsoft-standard-WSL2 amd64 | |
root@756afa3365f2:/# mkdir codebase | |
root@756afa3365f2:/# cd codebase/ | |
root@756afa3365f2:/codebase# git clone https://github.com/thanoojgithub/SpringDataREST.git | |
Cloning into 'SpringDataREST'... | |
remote: Enumerating objects: 120, done. | |
remote: Counting objects: 100% (120/120), done. | |
remote: Compressing objects: 100% (92/92), done. | |
remote: Total 120 (delta 37), reused 28 (delta 0), pack-reused 0 (from 0) | |
Receiving objects: 100% (120/120), 70.23 KiB | 1.46 MiB/s, done. | |
Resolving deltas: 100% (37/37), done. | |
root@756afa3365f2:/codebase# ls -ltr | |
total 4 | |
drwxr-xr-x 6 root root 4096 Nov 30 07:37 SpringDataREST | |
root@756afa3365f2:/codebase# cd SpringDataREST/ | |
root@756afa3365f2:/codebase/SpringDataREST# ls -ltr | |
total 48 | |
drwxr-xr-x 4 root root 4096 Nov 30 07:37 src | |
-rw-r--r-- 1 root root 36 Nov 30 07:37 settings.gradle.kts | |
-rw-r--r-- 1 root root 2872 Nov 30 07:37 gradlew.bat | |
-rw-r--r-- 1 root root 8762 Nov 30 07:37 gradlew | |
drwxr-xr-x 3 root root 4096 Nov 30 07:37 gradle | |
-rw-r--r-- 1 root root 666 Nov 30 07:37 build.gradle.kts | |
-rw-r--r-- 1 root root 580 Nov 30 07:37 README.md | |
-rw-r--r-- 1 root root 6352 Nov 30 07:37 HELP.md | |
-rw-r--r-- 1 root root 153 Nov 30 07:37 Dockerfile | |
root@756afa3365f2:/codebase/SpringDataREST# gradle clean install | |
root@756afa3365f2:/codebase/SpringDataREST# exit | |
exit | |
PS C:\Users\Admin> docker-compose down | |
[+] Running 2/2 | |
✔ Container ubuntu_container Removed 11.4s | |
✔ Network admin_default Removed 0.2s | |
PS C:\Users\Admin> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
docker cp C:/Users/Admin/codebase/SpringDataREST/start-deps.sh ubuntu_container:/code