Skip to content

Instantly share code, notes, and snippets.

@Rajan-sust
Last active July 7, 2021 22:27
Show Gist options
  • Save Rajan-sust/79dc9182d71625df403d74757b57b270 to your computer and use it in GitHub Desktop.
Save Rajan-sust/79dc9182d71625df403d74757b57b270 to your computer and use it in GitHub Desktop.
How to dockerize a project?
FROM ubuntu:latest
WORKDIR /app
COPY main.sh .
10
20
30
40
50
#!/bin/bash
sum=0
while read num; do
sum=$((sum + num))
done < "${1}"
echo "sum is: ${sum}" > output.txt
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
# 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
# Run cmd
app$ bash main.sh input.txt
# Show generated output
app$ cat output.txt
@Rashedul
Copy link

Rashedul commented Jul 7, 2021

Was very useful, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment