first commit
This commit is contained in:
14
Dockerfile.bash
Normal file
14
Dockerfile.bash
Normal file
@@ -0,0 +1,14 @@
|
||||
# Use the official Ubuntu image as the base image
|
||||
FROM ubuntu:latest
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Copy the hello_world.sh script into the container
|
||||
COPY hello_world.sh .
|
||||
|
||||
# Make the script executable
|
||||
RUN chmod +x hello_world.sh
|
||||
|
||||
# Run the script
|
||||
CMD ["./hello_world.sh"]
|
||||
11
Dockerfile.python
Normal file
11
Dockerfile.python
Normal file
@@ -0,0 +1,11 @@
|
||||
# Use the official Python image as the base image
|
||||
FROM python:3.9.19
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Copy the hello_world.py script into the container
|
||||
COPY hello_world.py .
|
||||
|
||||
# Run the script
|
||||
CMD ["python3", "hello_world.py"]
|
||||
14
Dockerfile.python-alpine
Normal file
14
Dockerfile.python-alpine
Normal file
@@ -0,0 +1,14 @@
|
||||
# Use the official Python image as the base image
|
||||
FROM alpine:latest
|
||||
|
||||
# Install python
|
||||
RUN apk add --no-cache python3
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Copy the hello_world.py script into the container
|
||||
COPY hello_world-alpine.py .
|
||||
|
||||
# Run the script
|
||||
CMD ["python3", "hello_world-alpine.py"]
|
||||
13
hello_world-alpine.py
Normal file
13
hello_world-alpine.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import time
|
||||
|
||||
# Total duration in seconds (10 minutes * 60 seconds)
|
||||
duration = 10 * 60
|
||||
# Interval between messages in seconds
|
||||
interval = 5
|
||||
# End time calculation
|
||||
end_time = time.time() + duration
|
||||
|
||||
# Loop until the current time is less than the end time
|
||||
while time.time() < end_time:
|
||||
print("Hello world - from Python in Alpine!")
|
||||
time.sleep(interval)
|
||||
13
hello_world.py
Normal file
13
hello_world.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import time
|
||||
|
||||
# Total duration in seconds (10 minutes * 60 seconds)
|
||||
duration = 10 * 60
|
||||
# Interval between messages in seconds
|
||||
interval = 5
|
||||
# End time calculation
|
||||
end_time = time.time() + duration
|
||||
|
||||
# Loop until the current time is less than the end time
|
||||
while time.time() < end_time:
|
||||
print("Hello world - from Python!")
|
||||
time.sleep(interval)
|
||||
14
hello_world.sh
Executable file
14
hello_world.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Total duration in seconds (10 minutes * 60 seconds)
|
||||
DURATION=$((10 * 60))
|
||||
# Interval between messages in seconds
|
||||
INTERVAL=5
|
||||
# End time calculation
|
||||
END_TIME=$((SECONDS + DURATION))
|
||||
|
||||
# Loop until the current time is less than the end time
|
||||
while [ $SECONDS -lt $END_TIME ]; do
|
||||
echo "Hello world - from bash!"
|
||||
sleep $INTERVAL
|
||||
done
|
||||
31
readme.md
Normal file
31
readme.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Hello World in Docker
|
||||
|
||||
## Bash
|
||||
```bash
|
||||
docker buildx build -t hello-world-bash -f Dockerfile.bash .
|
||||
docker run --rm --name "helloWorldBash" hello-world-bash
|
||||
```
|
||||
|
||||
## Python
|
||||
```bash
|
||||
docker buildx build -t hello-world-python -f Dockerfile.python .
|
||||
docker run --rm -it --name "helloWorldPython" hello-world-python
|
||||
```
|
||||
|
||||
## Python in Alpine
|
||||
```bash
|
||||
docker buildx build -t hello-world-python-alpine -f Dockerfile.python-alpine .
|
||||
docker run --rm -it --name "helloWorldPythonAlpine" hello-world-python-alpine
|
||||
```
|
||||
|
||||
# Let's see how much space each image takes up
|
||||
```bash
|
||||
docker images
|
||||
```
|
||||
|
||||
```bash
|
||||
REPOSITORY TAG IMAGE ID CREATED SIZE
|
||||
hello-world-bash latest 7fab71e07670 21 seconds ago 101MB
|
||||
hello-world-python-alpine latest e42435db8b4a 30 minutes ago 53.4MB
|
||||
hello-world-python latest 9fe43bb44dca 47 minutes ago 1GB
|
||||
```
|
||||
Reference in New Issue
Block a user