Compare commits

...

6 Commits

Author SHA1 Message Date
fcffbdb8f5 Media 2024-01-12 11:00:39 +01:00
e12386decf Update media 2024-01-12 10:55:51 +01:00
fef5fbc220 Media 2024-01-12 10:49:15 +01:00
4c20c41426 Add application user 2024-01-12 10:29:26 +01:00
10966f3c1f Update drawing 2024-01-11 21:27:58 +01:00
bec5fc997e Tweaks 2024-01-11 14:25:28 +01:00
15 changed files with 5949 additions and 2102 deletions

88
README.md Normal file
View File

@ -0,0 +1,88 @@
## Uvod
- Docker je platforma za development, delivery i izvršavanje aplikacija
- Docker omogućava da se aplikacija izolira u repetativnoj okolini i odvoji od infrastrukture
[Features of Docker](https://www.geeksforgeeks.org/features-of-docker/):
- Open-source platform
- An Easy, lightweight, and consistent way of delivery of applications
- Fast and efficient development life cycle
- Segregation of duties
- Service-oriented architecture
- Security
- Scalability
- Reduction in size
- Image management
- Networking
- Volume management
## Struktura
- Dockerfile
- image
- container registry
- lokalni
- dockerhub
- AWS ECR
- container
## Dockerfile
- base image
- odabir najmanjeg funkcionalnog
- debian prije ubuntua
- debian-slim prije debiana
- alpine
- from scratch
- env varijable
## Docker image
- single stage build
- multistage build
## Docker container
run, publish port 3000:
```
docker run --name api-server-3000 --publish 3000:3000 --env CONTAINER_NAME="Awesome API server on port 3000" -d api-server
```
run, publish port 3001:
```
docker run --name api-server-3001 --publish 3001:3000 --env CONTAINER_NAME="Awesome API server on port 3001" -d api-server
```
run, publish port 3002:
```
docker run --name api-server-3002 --publish 3002:3000 --env CONTAINER_NAME="Awesome API server on port 3002" -d api-server
```
# Media
## Docker vs VM
![Docker vs VM](media/docker-vs-vm.svg)
## Docker elements
![Docker elements](media/docker-elements.svg)
## Dockerfile layers
![Dockerfile layers](media/dockerfile-layers.svg)
## Port publishing
![Port publishing](media/port-publishing.svg)
## Horizontal scaling
![Horizontal scaling](media/horizontal-scaling.svg)
## Volumes
![Volumes](media/volumes.png)

View File

@ -1,5 +1,10 @@
FROM python:3.11-slim-bookworm
# uid to run application
ARG USER=1000
# gid to run application
ARG USER_GROUP=1000
# set virtual env path
ENV \
PATH=/venv/bin:$PATH
@ -13,11 +18,15 @@ WORKDIR /app
# copy app files to /app directory
COPY ./app .
# install dependencies
# set permissions to log directory and install dependencies
RUN \
chown -R ${USER}:${USER_GROUP} /app/log && \
python -m venv /venv && \
pip install -r requirements.txt
# set user to run application
USER ${USER}:${USER_GROUP}
# start shell script when container starts
ENTRYPOINT ["/app/run.sh"]

View File

@ -1,13 +1,14 @@
IMAGE_NAME=api-server
CONTAINER_NAME=api-server
build: clean
@docker build \
--progress=plain \
--no-cache \
--tag $(IMAGE_NAME) \
.
run:
@docker run \
--name $(IMAGE_NAME) \
@ -16,6 +17,7 @@ run:
--detach \
$(CONTAINER_NAME)
run-mount-log:
@docker run \
--name $(IMAGE_NAME) \

File diff suppressed because it is too large Load Diff

21
media/docker-elements.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 181 KiB

21
media/docker-vs-vm.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 299 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 103 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 44 KiB

21
media/port-publishing.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 120 KiB

BIN
media/volumes.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 MiB

86
media/volumes.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 68 KiB

View File

@ -1,5 +1,10 @@
FROM python:3.11-slim-bookworm
# uid to run application
ARG USER=1000
# gid to run application
ARG USER_GROUP=1000
# set virtual env path
ENV \
PATH=/venv/bin:$PATH
@ -19,11 +24,15 @@ RUN \
# copy app files to /app directory
COPY ./app .
# install dependencies && cleanup
# set permissions to log directory and install dependencies && cleanup
RUN \
chown -R ${USER}:${USER_GROUP} /app/log && \
pip install -r requirements.txt && \
apt purge --auto-remove -y
# set user to run application
USER ${USER}:${USER_GROUP}
# start shell script when container starts
ENTRYPOINT ["/app/run.sh"]

View File

@ -23,6 +23,11 @@ RUN \
FROM python:3.11-slim-bookworm
# uid to run application
ARG USER=1000
# gid to run application
ARG USER_GROUP=1000
# set virtual env path
ENV \
PATH=/venv/bin:$PATH
@ -38,11 +43,11 @@ COPY --from=install-dependencies /venv /venv
# copy app files to /app directory
COPY ./app .
RUN ls -alF /
RUN ls -alF /venv
RUN ls -alF /venv/bin
RUN ls -alF /app
# set permissions to log directory
RUN chown -R ${USER}:${USER_GROUP} /app/log
# set user to run application
USER ${USER}:${USER_GROUP}
# start shell script when container starts
ENTRYPOINT ["/app/run.sh"]

View File

@ -1,12 +1,14 @@
IMAGE_NAME=api-server-ms
CONTAINER_NAME=api-server-ms
build: clean
@docker build \
--progress=plain \
--tag $(IMAGE_NAME) \
.
build-multistage: clean
@docker build \
--progress=plain \
@ -14,14 +16,17 @@ build-multistage: clean
--file Dockerfile.multistage \
.
run:
@docker run \
--name $(IMAGE_NAME) \
--publish 3000:3000 \
--env CONTAINER_NAME="Awesome API server" \
--volume /var/log/api-server:/app/log \
--detach \
$(CONTAINER_NAME)
clean:
- @docker stop $(CONTAINER_NAME)
- @docker rm $(CONTAINER_NAME)