Docker Fundamentals & Container Basics (Multi-Lang Hello World)
This commit is contained in:
parent
59b7bd3720
commit
4e6ff4fbae
|
@ -0,0 +1,24 @@
|
|||
FROM ubuntu:22.04
|
||||
|
||||
# Install Go
|
||||
RUN apt-get update && \
|
||||
apt-get install -y wget tar git build-essential && \
|
||||
wget https://go.dev/dl/go1.21.1.linux-amd64.tar.gz && \
|
||||
tar -C /usr/local -xzf go1.21.1.linux-amd64.tar.gz && \
|
||||
rm go1.21.1.linux-amd64.tar.gz
|
||||
|
||||
# Tambahkan Go ke PATH
|
||||
ENV PATH="/usr/local/go/bin:${PATH}"
|
||||
|
||||
# Buat direktori kerja
|
||||
WORKDIR /app
|
||||
|
||||
# Salin source code
|
||||
COPY main.go .
|
||||
|
||||
# Compile Go ke binary
|
||||
RUN go build -o hello main.go
|
||||
|
||||
# Jalankan binary
|
||||
CMD ["./hello"]
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for {
|
||||
fmt.Println("Hello from Go Inside Docker!")
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
FROM ubuntu:22.04
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Install OpenJDK dan tools dasar
|
||||
RUN apt-get update && \
|
||||
apt-get install -y openjdk-17-jdk && \
|
||||
apt-get clean
|
||||
|
||||
# Set direktori kerja
|
||||
WORKDIR /app
|
||||
|
||||
# Salin file java
|
||||
COPY Hello.java .
|
||||
|
||||
# Compile file Java
|
||||
RUN javac Hello.java
|
||||
|
||||
# Jalankan program
|
||||
CMD ["java", "Hello"]
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
public class Hello {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello from Java Inside Docker!");
|
||||
|
||||
while (true) {
|
||||
System.out.println("App is running...");
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println("Loop interrupted");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
FROM ubuntu:22.04
|
||||
|
||||
# Install curl, Node.js, dan npm
|
||||
RUN apt-get update && \
|
||||
apt-get install -y curl && \
|
||||
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
|
||||
apt-get install -y nodejs
|
||||
|
||||
# Buat direktori kerja
|
||||
WORKDIR /app
|
||||
|
||||
# Salin file aplikasi
|
||||
COPY app.js .
|
||||
|
||||
# Jalankan app.js
|
||||
CMD ["node", "app.js"]
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
console.log("Starting loop...");
|
||||
|
||||
setInterval(() => {
|
||||
console.log("App is running...");
|
||||
}, 5000);
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"name": "hello-node",
|
||||
"version": "1.0.0",
|
||||
"main": "app.js",
|
||||
"scripts": {
|
||||
"start": "node app.js"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
FROM ubuntu:20.04
|
||||
|
||||
# Non-interaktif untuk menghindari prompt saat install
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Install Python
|
||||
RUN apt-get update && \
|
||||
apt-get install -y python3 && \
|
||||
apt-get clean
|
||||
|
||||
WORKDIR /app
|
||||
COPY app.py .
|
||||
|
||||
CMD ["python3", "app.py"]
|
|
@ -0,0 +1,8 @@
|
|||
# app.py
|
||||
import time
|
||||
|
||||
print("Starting loop...")
|
||||
|
||||
while True:
|
||||
print("App is running...")
|
||||
time.sleep(5)
|
Loading…
Reference in New Issue