Last active
July 7, 2021 22:27
-
-
Save Rajan-sust/79dc9182d71625df403d74757b57b270 to your computer and use it in GitHub Desktop.
How to dockerize a project?
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
FROM ubuntu:latest | |
WORKDIR /app | |
COPY main.sh . |
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
10 | |
20 | |
30 | |
40 | |
50 |
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 | |
sum=0 | |
while read num; do | |
sum=$((sum + num)) | |
done < "${1}" | |
echo "sum is: ${sum}" > output.txt |
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
1. A simple shell application that will take list of numbers as input and shows sum as output. | |
2. Input will be a text file and filename will be a cmd line argument. | |
3. Output will be redirected to a text file. | |
4. Firstly, run the program from local computer. | |
5. Dockerize the application for making platform independent. | |
* Directory structure for the project: | |
app | |
├── Dockerfile | |
├── input.txt | |
└── main.sh |
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
# Build docker for image creation | |
app$ sudo docker build --tag shellapp:latest . | |
# Run the docker container | |
app$ sudo docker run --name jelly_fish -v $PWD/input.txt:/app/input.txt -t shellapp:latest bash main.sh input.txt | |
# Show the output.txt generated within docker container | |
app$ sudo docker export jelly_fish > docker_container.tar | |
app$ mkdir docker_container | |
app$ tar -xf docker_container.tar -C ./docker_container/ | |
app$ cat ./docker_container/app/output.txt | |
# sum is: 150 |
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
# Run cmd | |
app$ bash main.sh input.txt | |
# Show generated output | |
app$ cat output.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Was very useful, thanks!