{"id":27171012,"url":"https://github.com/adamdawi/lab5-docker","last_synced_at":"2025-04-09T08:22:17.922Z","repository":{"id":285203090,"uuid":"954660958","full_name":"AdamDawi/lab5-docker","owner":"AdamDawi","description":"A Dockerfile using multi-stage builds to create a simple web app with a scratch base image and Nginx, displaying server IP, hostname, and app version. Includes health check and versioning.","archived":false,"fork":false,"pushed_at":"2025-04-08T19:09:02.000Z","size":3780,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T20:23:36.241Z","etag":null,"topics":["docker","healthcheck","multi-stage-build","nginx","versioning","web-application"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AdamDawi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-25T12:28:30.000Z","updated_at":"2025-04-08T19:21:07.000Z","dependencies_parsed_at":"2025-03-30T09:29:54.053Z","dependency_job_id":null,"html_url":"https://github.com/AdamDawi/lab5-docker","commit_stats":null,"previous_names":["adamdawi/lab5-docker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdamDawi%2Flab5-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdamDawi%2Flab5-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdamDawi%2Flab5-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdamDawi%2Flab5-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AdamDawi","download_url":"https://codeload.github.com/AdamDawi/lab5-docker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248000338,"owners_count":21031164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","healthcheck","multi-stage-build","nginx","versioning","web-application"],"created_at":"2025-04-09T08:22:17.269Z","updated_at":"2025-04-09T08:22:17.910Z","avatar_url":"https://github.com/AdamDawi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lab 5 — Docker\n\n[🇬🇧 English](#english-version) | [🇵🇱 Polski](#wersja-polska)\n\n---\n\n## English version\n\n### Stage One in Dockerfile (stage 1)\n\n### Creating `Dockerfile_stage_1`:\n1. Copying `package.json` before the application code (`index.js`):\n   - Docker caches the `RUN npm install` layer if `package.json` remains unchanged.\n   - This means that if only `index.js` is modified, re-installing dependencies is not required, significantly speeding up the build process.\n   - Each `RUN` and `COPY` instruction creates a new layer – using two separate `COPY` instructions (first for `package.json`, then for the application code) increases the number of layers but allows better caching, which speeds up future builds. It's a trade-off between optimization and flexibility.\n\n#### Command to build the image:\n```bash\ndocker build --build-arg VERSION=1.0.1 -f Dockerfile_stage_1 -t task_1 .\n```\n\n#### Output of the build command:\n```\n[+] Building 1.9s (10/10) FINISHED\n[...output truncated for brevity...]\n```\n\n#### Command to run the container:\n```bash\ndocker run -d --rm --name task_1_test -p 8080:8080 task_1\n```\n\n#### Output of the run command:\n```\nc40a3b6b0564bce7b409836767d4462fad7cbb4749810869352a50bbda2000d3\n```\n\n#### Command to display running containers:\n```bash\ndocker ps\n```\n\n#### Output of the ps command:\n```\nCONTAINER ID   IMAGE     COMMAND       CREATED             STATUS             PORTS                    NAMES\nc40a3b6b0564   task_1    \"npm start\"   About a minute ago  Up About a minute  0.0.0.0:8080-\u003e8080/tcp   task_1_test\n```\n\n#### Screenshot showing the running web app:\n![Image](https://github.com/user-attachments/assets/136db71a-4f4a-4119-a8cb-932ceb5c4094)\n\n---\n\n### Stage Two in Dockerfile (stage 1 and 2)\n\n#### Command to build the image:\n```bash\ndocker build --build-arg VERSION=1.0.1 -f Dockerfile_stage_1_and_2 -t task_2 .\n```\n\n#### Output of the build command:\n```\n[+] Building 8.2s (16/16) FINISHED\n[...output truncated for brevity...]\n```\n\n#### Command to run the container:\n```bash\ndocker run -d --rm --name task_2_test -p 80:80 task_2\n```\n\n#### Output of the run command:\n```\nf8edb21b1cd622fc36137e8169fa60eabfca003f0003072fea4a2b063f8e9638\n```\n\n#### Command to display running containers:\n```bash\ndocker ps\n```\n\n#### Output of the ps command:\n```\nCONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS                    PORTS                          NAMES\nf8edb21b1cd6   task_2    \"/docker-entrypoint.…\"   46 seconds ago  Up 46 seconds (healthy)   0.0.0.0:80-\u003e80/tcp, 8080/tcp   task_2_test\n```\n\n#### Screenshot showing the running web app:\n![Image](https://github.com/user-attachments/assets/afa5ff55-54ed-4597-b52d-16ee7406e610)\n\n## Wersja polska\n\n### Etap pierwszy w pliku Dockerfile (stage 1)\n#### Tworzenie pliku Dockerfile_stage_1:\n1. Kopiowanie package.json przed kodem aplikacji (index.js)\n    - Docker buforuje warstwę RUN npm install, jeśli package.json pozostaje bez zmian.\n    - Dzięki temu, jeśli zostanie zmodyfikowany tylko index.js, ponowna instalacja zależności nie będzie konieczna, co znacząco przyspieszy budowanie obrazu.\n    - Każda instrukcja RUN i COPY tworzy nową warstwę – użycie dwóch oddzielnych COPY (najpierw package.json, potem kod aplikacji) zwiększa liczbę warstw, ale pozwala na lepsze wykorzystanie cache, co przyspiesza kolejne budowy obrazu. To kompromis między optymalizacją a elastycznością.\n\n#### Polecenie do zbudowania obrazu:\n```bash\ndocker build --build-arg VERSION=1.0.1 -f Dockerfile_stage_1 -t zadanie_1 .\n```\n#### Wynik działania polecenia build:\n```\n[+] Building 1.9s (10/10) FINISHED                                                                                                                                                                                docker:desktop-linux\n =\u003e [internal] load build definition from Dockerfile_stage_1                                                                                                                                                                      0.0s\n =\u003e =\u003e transferring dockerfile: 638B                                                                                                                                                                                              0.0s\n =\u003e [internal] load .dockerignore                                                                                                                                                                                                 0.0s\n =\u003e =\u003e transferring context: 671B                                                                                                                                                                                                 0.0s\n =\u003e [internal] load build context                                                                                                                                                                                                 0.0s\n =\u003e =\u003e transferring context: 1.92kB                                                                                                                                                                                               0.0s\n =\u003e CACHED [1/6] ADD alpine-minirootfs-3.21.3-aarch64.tar /                                                                                                                                                                       0.0s\n =\u003e CACHED [2/6] WORKDIR /usr/app                                                                                                                                                                                                 0.0s\n =\u003e CACHED [3/6] RUN apk add --no-cache nodejs npm                                                                                                                                                                                0.0s\n =\u003e CACHED [4/6] COPY ./package.json ./                                                                                                                                                                                           0.0s\n =\u003e CACHED [5/6] RUN npm install                                                                                                                                                                                                  0.0s\n =\u003e [6/6] COPY ./index.js ./                                                                                                                                                                                                      0.1s\n =\u003e exporting to image                                                                                                                                                                                                            1.6s\n =\u003e =\u003e exporting layers                                                                                                                                                                                                           0.1s\n =\u003e =\u003e exporting manifest sha256:126ffebcfb420ff9c8d86bc6585424c1fdf2de569eeb28689a58baff9f94ea61                                                                                                                                 0.0s\n =\u003e =\u003e exporting config sha256:fd6548265e0357c88f11aeda64cfaf87f73c0bdd7412e871d8117b5caf0e6672                                                                                                                                   0.0s\n =\u003e =\u003e exporting attestation manifest sha256:965a2e424a47df2642ee8ef4304237b9e59d2b745927db942af8c8cc2db0613b                                                                                                                     0.0s \n =\u003e =\u003e exporting manifest list sha256:503ef94b2b6568f04ed942ced269b125609fa7e0f7059667e68c2649a6709ddf                                                                                                                            0.0s \n =\u003e =\u003e naming to docker.io/library/zadanie_1:latest                                                                                                                                                                               0.0s \n =\u003e =\u003e unpacking to docker.io/library/zadanie_1:latest                                                                                                                                                                            1.3s \n\nView build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/vif5ezpwmclv5nqj2xj00egjp\n```\n\n#### Polecenie do uruchomienia kontenera:\n```bash\ndocker run -d --rm --name zadanie_1_test -p 8080:8080 zadanie_1\n```\n#### Wynik działania polecenia run:\n```\nc40a3b6b0564bce7b409836767d4462fad7cbb4749810869352a50bbda2000d3\n```\n\n#### Polecenie do wyświetlenia uruchomionych kontenerów:\n```bash\ndocker ps\n```\n#### Wynik działania polecenia ps:\n```\nCONTAINER ID   IMAGE       COMMAND       CREATED              STATUS              PORTS                    NAMES\nc40a3b6b0564   zadanie_1   \"npm start\"   About a minute ago   Up About a minute   0.0.0.0:8080-\u003e8080/tcp   zadanie_1_test\n```\n\n#### Zdjęcie pokazujące działanie aplikacji webowej:\n![Image](https://github.com/user-attachments/assets/136db71a-4f4a-4119-a8cb-932ceb5c4094)\n\n### Etap drugi w pliku Dockerfile (stage 1 i 2)\n\n#### Polecenie do zbudowania obrazu:\n```bash\ndocker build --build-arg VERSION=1.0.1 -f Dockerfile_stage_1_and_2 -t zadanie_2 .\n```\n\n#### Wynik działania polecenia build:\n```\n[+] Building 8.2s (16/16) FINISHED                                                                                                                                                                                docker:desktop-linux \n =\u003e [internal] load build definition from Dockerfile_stage_1_and_2                                                                                                                                                                0.0s \n =\u003e =\u003e transferring dockerfile: 1.24kB                                                                                                                                                                                            0.0s \n =\u003e [internal] load metadata for docker.io/library/nginx:latest                                                                                                                                                                   0.0s \n =\u003e [internal] load .dockerignore                                                                                                                                                                                                 0.0s \n =\u003e =\u003e transferring context: 671B                                                                                                                                                                                                 0.0s \n =\u003e [internal] load build context                                                                                                                                                                                                 0.0s \n =\u003e =\u003e transferring context: 151B                                                                                                                                                                                                 0.0s \n =\u003e [stage-1 1/5] FROM docker.io/library/nginx:latest@sha256:124b44bfc9ccd1f3cedf4b592d4d1e8bddb78b51ec2ed5056c52d3692baebc19                                                                                                     0.0s \n =\u003e =\u003e resolve docker.io/library/nginx:latest@sha256:124b44bfc9ccd1f3cedf4b592d4d1e8bddb78b51ec2ed5056c52d3692baebc19                                                                                                             0.0s \n =\u003e CACHED [stage-1 2/5] RUN apt update \u0026\u0026 apt install -y curl nodejs npm                                                                                                                                                         0.0s \n =\u003e CACHED [stage-1 3/5] WORKDIR /usr/app                                                                                                                                                                                         0.0s \n =\u003e CACHED [build-stage 1/6] ADD alpine-minirootfs-3.21.3-aarch64.tar /                                                                                                                                                           0.0s \n =\u003e CACHED [build-stage 2/6] WORKDIR /usr/app                                                                                                                                                                                     0.0s \n =\u003e CACHED [build-stage 3/6] RUN apk add --no-cache nodejs npm                                                                                                                                                                    0.0s \n =\u003e CACHED [build-stage 4/6] COPY ./package.json ./                                                                                                                                                                               0.0s \n =\u003e CACHED [build-stage 5/6] RUN npm install                                                                                                                                                                                      0.0s\n =\u003e CACHED [build-stage 6/6] COPY ./index.js ./                                                                                                                                                                                   0.0s\n =\u003e CACHED [stage-1 4/5] COPY --from=build-stage /usr/app /usr/app                                                                                                                                                                0.0s\n =\u003e CACHED [stage-1 5/5] COPY default.conf /etc/nginx/conf.d/default.conf                                                                                                                                                         0.0s\n =\u003e exporting to image                                                                                                                                                                                                            8.0s\n =\u003e =\u003e exporting layers                                                                                                                                                                                                           0.0s\n =\u003e =\u003e exporting manifest sha256:7a11ded8b717a99e800efe7a50e959eea4a5956696b10a745d590a628572bf6a                                                                                                                                 0.0s\n =\u003e =\u003e exporting config sha256:7dfe85cce9393b68c77f297c43cd0c60d3a2250f19ddce2aa5a502f78ef68f53                                                                                                                                   0.0s\n =\u003e =\u003e exporting attestation manifest sha256:2143cad27cac540d7f839e8c582b9630b5af246f0a71ddee3fe2487d4347d633                                                                                                                     0.0s\n =\u003e =\u003e exporting manifest list sha256:1da4637486e3023ed226c7462a3340c1fe43442cd2c9ca17fc9a815e63c38f00                                                                                                                            0.0s \n =\u003e =\u003e naming to docker.io/library/zadanie_2:latest                                                                                                                                                                               0.0s \n =\u003e =\u003e unpacking to docker.io/library/zadanie_2:latest                                                                                                                                                                            7.9s \n\nView build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/g8q78wfz3ny7a0rjxu0puqpj8\n```\n\n#### Polecenie do uruchomienia kontenera:\n```bash\ndocker run -d --rm --name zadanie_2_test -p 80:80 zadanie_2\n```\n#### Wynik działania polecenia run:\n```\nf8edb21b1cd622fc36137e8169fa60eabfca003f0003072fea4a2b063f8e9638\n```\n\n#### Polecenie do wyświetlenia uruchomionych kontenerów:\n```bash\ndocker ps\n```\n#### Wynik działania polecenia ps:\n```\nCONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS                    PORTS                          NAMES\nf8edb21b1cd6   zadanie_2   \"/docker-entrypoint.…\"   46 seconds ago   Up 46 seconds (healthy)   0.0.0.0:80-\u003e80/tcp, 8080/tcp   zadanie_2_test\n```\n\n#### Zdjęcie pokazujące działanie aplikacji webowej:\n![Image](https://github.com/user-attachments/assets/afa5ff55-54ed-4597-b52d-16ee7406e610)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamdawi%2Flab5-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamdawi%2Flab5-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamdawi%2Flab5-docker/lists"}