You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/03_first_rest_api/05_make_request_to_rest_api/README.md
+8-7
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
---
2
2
title: How to interact with your REST API
3
3
description: Use Postman and Insomnia REST Client to interact with your REST API.
4
+
ctslug: how-to-interact-with-your-rest-api
4
5
---
5
6
6
7
# How to make a request to a REST API
@@ -28,11 +29,11 @@ Start by [downloading Insomnia REST Client](https://insomnia.rest/).
28
29
29
30
Once you've opened it, create a Project. I would call it "REST APIs with Flask and Python".
30
31
31
-

32
+

32
33
33
34
Then, create a new Request Collection. Call it "Stores REST API".
34
35
35
-

36
+

36
37
37
38
In the Request Collection, we can now add requests! Each request has a few parts:
Make a new request using the Insomnia interface. First, use the dropdown to start:
47
48
48
-

49
+

49
50
50
51
Then enter the request name. Leave the method as `GET`:
51
52
52
-

53
+

53
54
54
55
Once you're done, you will see your request in the collection:
55
56
56
-

57
+

57
58
58
59
Next up, enter the URL for your request. Here we will be requesting the `/store` endpoint. Remember to include your Base URL as well:
59
60
60
-

61
+

61
62
62
63
Once you're done, make sure that your Flask app is running! If it isn't, remember to activate your virtual environment first and then run the app:
63
64
@@ -74,6 +75,6 @@ If you get an error, read it carefully and make sure that no other Flask app is
74
75
75
76
Once your Flask app is running, you can hit "Send" on the Insomnia client, and you should see the JSON come back from your API!
76
77
77
-

78
+

78
79
79
80
If that worked and you can see your JSON, you're good to go! You've made your first API request. Now we can continue developing our REST API, remembering to always create new Requests in Insomnia and test our code as we go along!
Copy file name to clipboardExpand all lines: docs/docs/04_docker_intro/01_what_is_docker_container/README.md
+80-4
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,15 @@
1
-
# What is a Docker container?
1
+
---
2
+
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.
4
+
---
5
+
6
+
# What are Docker images and containers?
2
7
3
8
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.
Looks similar, but the `docker -> container` section is much more efficient than running a VM because it **uses the host's kernel** instead of running its own.
20
25
@@ -85,4 +90,75 @@ Yes!
85
90
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.
86
91
:::
87
92
88
-
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.
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`
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.
Copy file name to clipboardExpand all lines: docs/docs/04_docker_intro/02_run_docker_container/README.md
+6-1
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,8 @@
1
+
---
2
+
ctslug: how-to-run-a-docker-container
3
+
description: Learn how to run a Docker container with your REST API using Docker Desktop.
4
+
---
5
+
1
6
# How to run a Docker container
2
7
3
8
## Install Docker Desktop
@@ -122,6 +127,6 @@ docker run -dp 5001:5000 rest-apis-flask-python
122
127
123
128
Try making requests using the URL `127.0.0.1:5000` with Insomnia REST Client or Postman, and you should see it working well!
124
129
125
-

130
+

0 commit comments