Skip to content

Commit f526a16

Browse files
authored
Merge pull request #142 from tecladocode/jose/update-buster-to-bookworm
Update `buster` to `bookworm`
2 parents 58398dc + a7c8e1b commit f526a16

File tree

5 files changed

+76
-77
lines changed

5 files changed

+76
-77
lines changed

docs/docs/04_docker_intro/01_what_is_docker_container/README.md

+74-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
ctslug: what-is-a-docker-container
3+
description: Learn what Docker images and containers are, and how we can use them to distribute and run our applications.
34
---
45

5-
# What is a Docker container?
6+
# What are Docker images and containers?
67

78
I'm sure you have heard of the term "Virtual Machine". A virtual machine is an emulation of an Operating System. For example, if you run a Windows virtual machine on your MacOS computer, it will run a whole copy of Windows so you can run Windows programs.
89

@@ -89,4 +90,75 @@ Yes!
8990
When we build our Docker image, we will be building it _on top of_ other, pre-built, existing images. Those images come with the lower-level requirements such as compilers, the C language, and most utilities and programs we need.
9091
:::
9192

92-
Let's take a look at Docker images in the next lecture.
93+
## What is a Docker image?
94+
95+
A Docker image is a snapshot of source code, libraries, dependencies, tools, and everything else (except the Operating System kernel!) that a container needs to run.
96+
97+
There are many pre-built images that you can use. For example, some come with Ubuntu (a Linux distribution). Others come with Ubuntu and Python already installed. You can also make your own images that already have Flask installed (as well as other dependencies your app needs).
98+
99+
:::info Comes with Ubuntu?
100+
In the last lecture I mentioned that Docker containers use the host OS kernel, so why does the container need Ubuntu?
101+
102+
Remember that operating systems are kernel + programs/libraries. Although the container uses the host kernel, we may still need a lot of programs/libraries that Ubuntu ships with. An example might be a C language compiler!
103+
:::
104+
105+
This is how you define a Docker image. I'll guide you through how to do this in the next lecture, but bear with me for a second:
106+
107+
```dockerfile
108+
FROM python:3.10
109+
EXPOSE 5000
110+
WORKDIR /app
111+
RUN pip install flask
112+
COPY . .
113+
CMD ["flask", "run", "--host", "0.0.0.0"]
114+
```
115+
116+
This is a `Dockerfile`, a definition of how to create a Docker image. Once you have this file, you can ask Docker to create the Docker image. Then, after creating the Docker image, you can ask Docker to run it as a container.
117+
118+
```
119+
Dockerfile ---build--> docker image ---run--> docker container
120+
```
121+
122+
In this `Dockerfile` you can see the first line: `FROM python:3.10`. This tells Docker to first download the `python:3.10` image (an image someone else already created), and once that image is created, run the following commands.
123+
124+
:::info What's in the Python image?
125+
The `python:3.10` image is also built using a `Dockerfile`! You can see the `Dockerfile` for it [here](https://github.com/docker-library/python/blob/master/3.10/bookworm/Dockerfile).
126+
127+
You can see it comes `FROM` another image. There is usually a chain of these, images built upon other images, until you reach the base image. In this case, the [base image](https://github.com/docker-library/buildpack-deps/blob/master/debian/bookworm/Dockerfile) is running Debian (a Linux distribution).
128+
129+
<details>
130+
<summary>Where is the base image!?</summary>
131+
<div>
132+
<div>
133+
134+
If you really want to go deep, you will be able to find...
135+
136+
- The [`python3.10:bookworm`](https://github.com/docker-library/python/blob/master/3.10/bookworm/Dockerfile) image builds on `buildpack-deps:bookworm`
137+
- [`buildpack-deps:bookworm`](https://github.com/docker-library/buildpack-deps/blob/master/debian/bookworm/Dockerfile) builds on `buildpack-deps:bookworm-scm`
138+
- [`buildpack-deps:bookworm-scm`](https://github.com/docker-library/buildpack-deps/blob/master/debian/bookworm/scm/Dockerfile) builds on `buildpack-deps:bookworm-curl`
139+
- [`buildpack-deps:bookworm-curl`](https://github.com/docker-library/buildpack-deps/blob/master/debian/bookworm/curl/Dockerfile) builds on `debian:bookworm`
140+
- [`debian:bookworm`](https://github.com/debuerreotype/docker-debian-artifacts/blob/f7257ef5b83f6b64385edddeae2d2ba7d1b34935/bookworm/Dockerfile) looks really weird!
141+
142+
Eventually, the base image has to physically include the files that make up the operating system. In that last image, that's the Debian OS files that the maintainers have deemed necessary for the `bookworm` image.
143+
144+
</div>
145+
</div>
146+
</details>
147+
148+
So, why the chain?
149+
150+
Three main reasons:
151+
152+
1. So you don't have to write a super long and complex `Dockerfile` which contains everything you need.
153+
2. So pre-published images can be shared online, and all you have to do is download them.
154+
3. So when your own images use the same base image, Docker in your computer only downloads the base image once, saving you a lot of disk space.
155+
:::
156+
157+
Back to our `Dockerfile`. The commands after `FROM...` are specific to our use case, and do things like install requirements, copy our source code into the image, and tell Docker what command to run when we start a container from this image.
158+
159+
This separation between images and containers is interesting because once the image is created you can ship it across the internet and:
160+
161+
- Share it with other developers.
162+
- Deploy it to servers.
163+
164+
Plus once you've downloaded the image (which can take a while), starting a container from it is almost instant since there's very little work to do.

docs/docs/04_docker_intro/03_run_docker_container/README.md renamed to docs/docs/04_docker_intro/02_run_docker_container/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
ctslug: how-to-run-a-docker-container
3+
description: Learn how to run a Docker container with your REST API using Docker Desktop.
34
---
45

56
# How to run a Docker container

docs/docs/04_docker_intro/02_what_is_docker_image/README.md

-75
This file was deleted.

docs/docs/04_docker_intro/04_in_depth_docker_tutorial/README.md renamed to docs/docs/04_docker_intro/03_in_depth_docker_tutorial/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
ctslug: in-depth-docker-tutorial
3+
description: My notes from the official Docker tutorial.
34
---
45

56
# In-depth Docker Tutorial

0 commit comments

Comments
 (0)