blob: 61f6caaf82b281986aad206f2b7bc0df7d06c293 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
---
title: Developing with Docker
author: gitlab.com/xlgmokha/developing-with-docker
date: 2020-06-10
---
# Developing with Docker
Mo Khan, Backend Engineer
Composition Analysis, GitLab
https://gitlab.com/xlgmokha
Inspired by: gitlab-org/gitlab#216082
# Agenda
* Build (build)
* Start/Stop container (ps, start, stop)
* Getting a shell (run vs exec)
* Analyzing an image (dive, docker layers)
* Shrinking an image (compression, discuss the trade offs of having more v. less layers)
* Sharing an image (push, pull, authn)
# Definitions
* Image: is like a class
* Container: is like an instance of a class (i.e. object)
# Definitions - Image/Container
* Person is a class definition
* "you" and "mo" are instances of the class Person
* instances of person can interact with one another
```ruby
class Person
def fist_bump(other_person)
end
end
mo = Person.new
you = Person.new
mo.first_bump(you)
```
# Definitions
Registry: stores images and makes them available to others
For example:
* https://index.docker.io
* https://registry.gitlab.com
```bash
curl -s -i https://index.docker.io/v2/alpine/tags/list
```
# Docker - Architecture
```plantuml
```
https://docs.docker.com/get-started/overview/#docker-architecture
# Dockerfile
A minimal Dockerfile:
```file
path: examples/001/Dockerfile
relative: true
lang: docker
```
https://docs.docker.com/engine/reference/builder/
# Dockerfile - FROM
> Initializes a build stage and sets a Base Image.
In this example the base image is alpine:latest.
By default this image will be fetched from the default Docker registry.
https://index.docker.io/
```file
path: examples/001/Dockerfile
relative: true
lang: docker
lines:
start: 0
end: 1
```
# Dockerfile - COPY
Copy "hello.rb" from the host to
"/usr/local/bin/hello" within the Docker image.
```file
path: examples/001/Dockerfile
relative: true
lang: docker
lines:
start: 1
end: 2
```
```terminal8
tree ./examples/001
```
# Dockerfile - RUN
RUN a command from within the image and make "hello" executable.
```file
path: examples/001/Dockerfile
relative: true
lang: docker
lines:
start: 2
end: 3
```
# Dockerfile - CMD
Set the default command to run when the docker image
is launched as a container.
```file
path: examples/001/Dockerfile
relative: true
lang: docker
lines:
start: 2
end: 3
```
# docker build
```terminal32
bash -il
```
# docker ps
# docker start
# docker stop
# docker run
# docker exec
# dive
* Describe layers
* Downloading multiple layers in parallel vs 1 large layer
# Compression (zstd)
More layers == more parallel download
Smaller layers == faster downloads
# Distribution
# docker push
# docker pull
# docker login
|