π§π½βπ»
Docker for devs

$ whoami
INSTALL
$ brew install --cask docker
$ whatis docker
$ help help
pwd, ls, cd, mkdir, touch
TAB
man, --help
$ uname -a
Darwin mbp2.local 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000
$ which ls
/bin/ls
$ ls -l /bin/ls
-rwxr-xr-x 1 root wheel 51888 Apr 6 21:52 /bin/ls
$ cat /etc/hosts
127.0.0.1 localhost
...
$ echo "Salut"
Salut
$ echo "Bonjour $USER !" > helloyou.txt
$ cat helloyou.txt
Bonjour abernier !
$ echo "Γa va bien ?" >> helloyou.txt
$ cat helloyou.txt
Bonjour abernier !
Γa va bien ?
$ cat >journal.txt
Cher journal,
Je t'Γ©cris ce matin depuis ma ligne de commande.
^D
$ more journal.txt
Cher journal,
Je t'Γ©cris ce matin depuis ma ligne de commande.
$ cat <<EOF >poem.txt
Lorem ipsum dolor sit amet
Consectetur adipiscing elit
Suspendisse at iaculis justo
nec consectetur dolor.
EOF
ctrl+E, ctrl+A, ctrl+U, ctrl+C
history, UP, DOWN, ctrl+r
chmod, chown, grep, find, ps, kill, ...
exit
$ docker --version
Docker version 20.10.16, build aa7e414
IMAGE



$ docker build
Dockerfile
1 FROM golang:1.11-alpine 2 3 RUN mkdir /app 4 COPY main.go /app 5 WORKDIR /app 6 7 RUN go build -o main . 8 9 EXPOSE 8080 8888 10 USER 1001 11 12 ENTRYPOINT ["/app/main"]


Dockerfile
$ docker build


$ docker images
$ docker run

$ docker run




Docker registry





$ docker push myimage


$ docker login

$ docker pull node




v18.3.0
$ docker run node --version
v16.15.1
$ docker run node:16-alpine --version
Usage: node [options] [ script.js ] [arguments]
...
-p, --print [...] evaluate script and print result
$ docker run node --help
3.141592653589793
$ docker run node -p "Math.PI"
π¬
Linux 4d78187ec8d3 5.10.104-linuxkit #1 SMP PREEMPT Thu Mar 17 17:05:54 UTC 2022 aarch64 GNU/Linux
$ docker run node uname -a
π
_____ < meh > ----- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
$ docker run node npm x cowsay meh
$ docker run node npm x qrip πHey!
Fun enough,
π·πΌββοΈ
Let's $ docker build
something (fun)
$ cat <<EOF >Dockerfile FROM ubuntu:22.04 RUN apt-get update && \ apt-get install -y nyancat CMD ["nyancat"] EOF $ docker build -t nyancat . $ docker images
$ mkdir -p ~/tmp && cd $_
πΏ
$ docker run -it nyancat

π»
$ docker ps
CONTAINER ID |
IMAGE |
COMMAND |
NAMES |
---|---|---|---|
84a1a868776d | nyancat |
"nyancat" |
relaxed_jang |
Dans un 2e terminal
$ docker exec 84a1a868776d uname Linux

Toujours dans notre 2e terminal
$ docker exec -it 84a1a868776d top
top - 09:53:13 up 17:40, 0 users, load average: 0.03, 0.30, 1.17 Tasks: 2 total, 2 running, 0 sleeping, 0 stopped, 0 zombie %Cpu(s): 1.2 us, 2.8 sy, 0.0 ni, 95.7 id, 0.3 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 2047140 total, 893648 free, 333412 used, 820080 buff/cache KiB Swap: 1048572 total, 949780 free, 98792 used. 1551004 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 4556 780 712 R 0.7 0.0 0:03.93 nyancat 65 root 20 0 36588 3176 2748 R 0.0 0.2 0:00.04 top
Toujours dans notre 2e terminal
π
ON AIR
$ docker kill 84a1a868776d
$ docker ps
CONTAINER ID |
IMAGE |
COMMAND |
NAMES |
---|
Toujours dans notre 2e terminal
π«
$ docker run -it nyancat /bin/sh # nyancat --help Terminal Nyancat usage: nyancat [-hitn] [-f frames]
...
Dans notre premier terminal
# exit
$
π³
ππ»
dockercra
React + Docker
Step 1 : build static app
$ mkdir -p ~/tmp/dockercra && cd $_ $ npm x create-react-app . β$ code .
β1 2 3 4 5 6 7 8 9 10 11 12
Dockerfile
FROM node:18-alpine
$ docker build --progress=plain -t dockercra . #6 [internal] load build context
Juste pour essayer
β1 2 3 4 5 6 7 8 9 10 11 12
Dockerfile
FROM node:18-alpine WORKDIR /app
β1 2 3 4 5 6 7 8 9 10 11 12
Dockerfile
FROM node:18-alpine WORKDIR /app COPY . ./
.dockerignore
β1
node_modules
$ docker build --progress=plain -t dockercra . #6 [internal] load build context #6 transferring context: 329B 0.5s done #6 DONE 0.5s
Toujours pour essayer
β1 2 3 4 5 6 7 8 9 10 11 12
Dockerfile
FROM node:18-alpine WORKDIR /app COPY package.json package-lock.json ./ RUN npm ci COPY . ./
β1 2 3 4 5 6 7 8 9 10 11 12
Dockerfile
FROM node:18-alpine WORKDIR /app COPY package.json package-lock.json ./ RUN npm ci COPY . ./ RUN npm run build
β1 2 3 4 5 6 7 8 9 10 11 12
Dockerfile
FROM node:18-alpine WORKDIR /app COPY package.json package-lock.json ./ RUN npm ci COPY . ./ RUN npm run build EXPOSE 3000 CMD ["npx", "-y", "serve", "-s", "build"]
$ docker build -t dockercra . $ docker images $ docker run -it --rm -p 3000:3000 dockercra
$ docker ps
$ docker exec -it a999c29eed5a /bin/sh
# ls
# exit
dans un autre terminal :
Deploy
on Heroku
π Heroku doc
$ heroku login $ heroku apps:create dockercraaa --stack=container $ docker login --username=_ --password=$(heroku auth:token) registry.heroku.com $ docker tag dockercra registry.heroku.com/dockercraaa/web $ docker push registry.heroku.com/dockercraaa/web $ heroku container:release web
π
THE END

π©π»βπ»
β€οΈ
Docker
By Antoine BERNIER
Docker
- 2,386