Studying docker

Add assignment

+86
+18
assignment-problem/instructions.txt
··· 1 + Dockerize BOTH apps - the Python and the Node app. 2 + 3 + 1) Create appropriate images for both apps (two separate images!). 4 + HINT: Have a brief look at the app code to configure your images correctly! 5 + 6 + 2) Launch a container for each created image, making sure, 7 + that the app inside the container works correctly and is usable. 8 + 9 + 3) Re-create both containers and assign names to both containers. 10 + Use these names to stop and restart both containers. 11 + 12 + 4) Clean up (remove) all stopped (and running) containers, 13 + clean up all created images. 14 + 15 + 5) Re-build the images - this time with names and tags assigned to them. 16 + 17 + 6) Run new containers based on the re-built images, ensuring that the containers 18 + are removed automatically when stopped.
+7
assignment-problem/node-app/Dockerfile
··· 1 + FROM node:20-alpine 2 + WORKDIR /app 3 + COPY package.json ./ 4 + RUN npm install 5 + COPY . /app 6 + EXPOSE 3000 7 + CMD ["node", "server.js"]
+14
assignment-problem/node-app/package.json
··· 1 + { 2 + "name": "app", 3 + "version": "1.0.0", 4 + "description": "", 5 + "main": "index.js", 6 + "scripts": { 7 + "test": "echo \"Error: no test specified\" && exit 1" 8 + }, 9 + "author": "", 10 + "license": "ISC", 11 + "dependencies": { 12 + "express": "^4.17.1" 13 + } 14 + }
+11
assignment-problem/node-app/server.js
··· 1 + const express = require('express'); 2 + 3 + const app = express(); 4 + 5 + app.get('/', (req, res) => { 6 + res.send(` 7 + <h1>Hello from inside the very basic Node app!</h1> 8 + `); 9 + }) 10 + 11 + app.listen(3000);
+5
assignment-problem/python-app/Dockerfile
··· 1 + FROM python:3.9-slim 2 + WORKDIR /app 3 + COPY . /app 4 + EXPOSE 80 5 + CMD ["python", "bmi.py"]
+31
assignment-problem/python-app/bmi.py
··· 1 + print('(1) Metric (m, kg) or (2) Non-Metric (ft, pounds)?') 2 + 3 + chosen_system = input('Please choose: ') 4 + 5 + if (chosen_system != '1' and chosen_system != '2'): 6 + print('You have to choose either metric or non-metric. Shutting down...') 7 + exit() 8 + 9 + height_unit = 'meters' 10 + weight_unit = 'kilograms' 11 + 12 + if (chosen_system == '2'): 13 + height_unit = 'feet' 14 + weight_unit = 'pounds' 15 + 16 + print('Please enter your height in ' + height_unit) 17 + user_height = float(input('Your height: ')) 18 + 19 + print('Please enter your weight in ' + weight_unit) 20 + user_weight = float(input('Your weight: ')) 21 + 22 + adj_height = user_height 23 + adj_weight = user_weight 24 + 25 + if (chosen_system == '2'): 26 + adj_height = user_height / 3.28084 27 + adj_weight = user_weight / 2.20462 28 + 29 + bmi = adj_weight / (adj_height * adj_height) 30 + 31 + print('Your body-mass-index: ' + str(bmi))