Skip to content

Commit

Permalink
part 1 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mluukkai committed Mar 9, 2024
1 parent 4bea732 commit e93c365
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ We hope that you enjoy the course and find it informative and engaging. Good luc

### Updating of the material for the 2024 edition

The 2024 edition of the course starts officially on 11th March. The material is currently being updated. At the time of writing (7th March) the following parts are already updated
The 2024 edition of the course starts officially on 11th March. The material is currently being updated. At the time of writing (9th March) the following parts have already been updated

- Part 1, up to and including section _Defining start conditions for the container_
- Part 1, up to and including section _Interacting with the container via volumes and ports_

You may continue already beyond the updated material but beware, there might be some outdated content!

Expand Down
12 changes: 6 additions & 6 deletions docs/part-1/section-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Defining start conditions for the container"
---

Next, we will start moving towards a more meaningful image. [yt-dlp](https://github.com/yt-dlp/yt-dlp) is a program that downloads YouTube videos. Let's add it to an image - but this time, we will change our process. Instead of our current process where we add things to the Dockerfile and hope it works, let's try another approach. This time we will open up an interactive session and test stuff before "storing" it in our Dockerfile.
Next, we will start moving towards a more meaningful image. [yt-dlp](https://github.com/yt-dlp/yt-dlp) is a program that downloads YouTube and [Imgur](https://imgur.com/) videos. Let's add it to an image - but this time, we will change our process. Instead of our current process where we add things to the Dockerfile and hope it works, let's try another approach. This time we will open up an interactive session and test stuff before "storing" it in our Dockerfile.

By following the [yt-dlp installation instructions](https://github.com/yt-dlp/yt-dlp/wiki/Installation) we will start as follows:

Expand Down Expand Up @@ -79,7 +79,7 @@ $ docker run yt-dlp
Type yt-dlp --help to see a list of all options.
```

So far so good. The natural way to use this image would be to give the URL as an argument but unfortunately it does not work:
So far so good. The natural way to use this image would be to give the URL as an argument but unfortunately, it does not work:

```console
$ docker run yt-dlp https://www.youtube.com/watch?v=uTZSILGTskA
Expand Down Expand Up @@ -119,18 +119,18 @@ And now it works like it should:

```console
$ docker build -t yt-dlp .
$ docker run yt-dlp https://www.youtube.com/watch?v=uTZSILGTskA
[youtube] Extracting URL: https://www.youtube.com/watch?v=uTZSILGTskA
$ docker run yt-dlp https://www.youtube.com/watch?v=XsqlHHTGQrw
[youtube] Extracting URL:https://www.youtube.com/watch?v=XsqlHHTGQrw
[youtube] uTZSILGTskA: Downloading webpage
[youtube] uTZSILGTskA: Downloading ios player API JSON
[youtube] uTZSILGTskA: Downloading android player API JSON
[youtube] uTZSILGTskA: Downloading m3u8 information
[info] uTZSILGTskA: Downloading 1 format(s): 22
[download] Destination: Burden Of Dreams V17 Nalle Hukkataival [uTZSILGTskA].mp4
[download] Destination: Master’s Programme in Computer Science | University of Helsinki [XsqlHHTGQrw].mp4
[download] 100% of 6.29MiB in 00:00:00 at 9.95MiB/s
```

With _ENTRYPOINT_ `docker run` now executed the combined combined `/usr/local/bin/yt-dlp https://www.youtube.com/watch?v=uTZSILGTskA` inside the container!
With _ENTRYPOINT_ `docker run` now executed the combined `/usr/local/bin/yt-dlp https://www.youtube.com/watch?v=uTZSILGTskA` inside the container!

`ENTRYPOINT` vs `CMD` can be confusing - in a properly set up image, such as our yt-dlp, the command represents an argument list for the entrypoint. By default, the entrypoint in Docker is set as `/bin/sh -c` and this is passed if no entrypoint is set. This is why giving the path to a script file as CMD works: you're giving the file as a parameter to `/bin/sh -c`.

Expand Down
26 changes: 13 additions & 13 deletions docs/part-1/section-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
title: "Interacting with the container via volumes and ports"
---

Let us get back to youtube downloader. It works yes, but it is quite laborous to get the download videos to the host machine.
Let us get back to yt-dlp. It works yes, but it is quite laborious to get the downloaded videos to the host machine.

We can use Docker [volumes](https://docs.docker.com/storage/volumes/) to make it easier to store the downloads outside the containers ephemeral storage. With [bind mount](https://docs.docker.com/storage/bind-mounts/) we can mount a file or directory from our own machine (the host machine) into the container.
We can use Docker [volumes](https://docs.docker.com/storage/volumes/) to make it easier to store the downloads outside the container's ephemeral storage. With [bind mount](https://docs.docker.com/storage/bind-mounts/) we can mount a file or directory from our own machine (the host machine) into the container.

Let's start a container with `-v` option, that requires an absolute path. We mount our current folder as `/mydir` in our container, overwriting everything that we have put in that folder in our Dockerfile.

```console
$ docker run -v "$(pwd):/mydir" youtube-dl https://imgur.com/JY5tHqr
$ docker run -v "$(pwd):/mydir" yt-dlp https://www.youtube.com/watch?v=DptFY_MszQs
```

So a volume is simply a folder (or a file) that is shared between the host machine and the container. If a file in volume is modified by a program that's running inside the container the changes are also saved from destruction when the container is shut down as the file exists on the host machine. This is the main use for volumes as otherwise all of the files wouldn't be accessible when restarting the container. Volumes also can be used to share files between containers and run programs that are able to load changed files.

In our youtube-dl we wanted to mount the whole directory since the files are fairly randomly named. If we wish to create a volume with only a single file we could also do that by pointing to it. For example `-v "$(pwd)/material.md:/mydir/material.md"` this way we could edit the material.md locally and have it change in the container (and vice versa). Note also that `-v` creates a directory if the file does not exist.
In our yt-dlp we wanted to mount the whole directory since the files are fairly randomly named. If we wish to create a volume with only a single file we could also do that by pointing to it. For example `-v "$(pwd)/material.md:/mydir/material.md"` this way we could edit the material.md locally and have it change in the container (and vice versa). Note also that `-v` creates a directory if the file does not exist.

## Exercise 1.9

Expand All @@ -23,7 +23,7 @@ In our youtube-dl we wanted to mount the whole directory since the files are fai
In this exercise we won't create a new Dockerfile.

Image `devopsdockeruh/simple-web-service` creates a timestamp every two seconds to `/usr/src/app/text.log` when it's not given a command. Start the
container with bind mount so that the logs are created into your filesystem.
container with a bind mount so that the logs are created into your filesystem.

Submit the command you used to complete the exercise.

Expand All @@ -33,17 +33,17 @@ Submit the command you used to complete the exercise.

## Allowing external connections into containers

The details on how programs communicate are not detailed in this course. Courses on Operating Systems and the Networking courses explain subjects in detail. In this course you only need to know the following simplified basics:
This course does not provide an in-depth exploration of inter-program communication mechanisms. If you want to learn that in-depth, you should look at classes about Operating Systems or Networking. Here, you just need to know a few simple things:

- Sending messages: Programs can send messages to [URL](https://en.wikipedia.org/wiki/URL) addresses such as this: http://127.0.0.1:3000 where http is the [_protocol_](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol), 127.0.0.1 is a ip address, and 3000 is a [_port_](<https://en.wikipedia.org/wiki/Port_(computer_networking)>). Note the ip part could also be a [_hostname_](https://en.wikipedia.org/wiki/Hostname): 127.0.0.1 is also called [_localhost_](https://en.wikipedia.org/wiki/Localhost) so instead you could use http://localhost:3000.
- Sending messages: Programs can send messages to [URL](https://en.wikipedia.org/wiki/URL) addresses such as this: http://127.0.0.1:3000 where HTTP is the [_protocol_](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol), 127.0.0.1 is an IP address, and 3000 is a [_port_](<https://en.wikipedia.org/wiki/Port_(computer_networking)>). Note the IP part could also be a [_hostname_](https://en.wikipedia.org/wiki/Hostname): 127.0.0.1 is also called [_localhost_](https://en.wikipedia.org/wiki/Localhost) so instead you could use http://localhost:3000.

- Receiving messages: Programs can be assigned to listen to any available port. If a program is listening for traffic on port 3000, and a message is sent to that port, it will receive it (and possibly process it).
- Receiving messages: Programs can be assigned to listen to any available port. If a program is listening for traffic on port 3000, and a message is sent to that port, the program will receive and possibly process it.

The address _127.0.0.1_ and hostname _localhost_ are special ones, they refer to the machine or container itself, so if you are on a container and send message to _localhost_, the target is the same container. Similarly, if you are sending the request from outside of a container to _localhost_, the target is your machine.
The address _127.0.0.1_ and hostname _localhost_ are special ones, they refer to the machine or container itself, so if you are on a container and send a message to _localhost_, the target is the same container. Similarly, if you are sending the request from outside of a container to _localhost_, the target is your machine.

You can map your host machine port to a container port.
It is possible to **map your host machine port to a container port**. For example, if you map port 1000 on your host machine to port 2000 in the container, and then you send a message to http://localhost:2000 on your computer, the container will get that message if it's listening to its port 2000.

Opening a connection from outside world to a Docker container happens in two steps:
Opening a connection from the outside world to a Docker container happens in two steps:

- Exposing port

Expand All @@ -63,7 +63,7 @@ If you leave out the host port and only specify the container port, Docker will
$ docker run -p 4567 app-in-port
```

We could also limit connections to certain protocol only, e.g. udp by adding the protocol at the end: `EXPOSE <port>/udp` and `-p <host-port>:<container-port>/udp`.
We could also limit connections to a certain protocol only, e.g. UDP by adding the protocol at the end: `EXPOSE <port>/udp` and `-p <host-port>:<container-port>/udp`.

:::tip Security reminder: Opening a door to the internet

Expand All @@ -83,7 +83,7 @@ Usually, this isn't risky. But depending on the application, it is something you

In this exercise, we won't create a new Dockerfile.

The image `devopsdockeruh/simple-web-service` will start a web service in port `8080` when given the argument "server". In [Exercise 1.8](/part-1/section-3#exercises-17---18) you already did a image that can be used to run the web service without any argument.
The image `devopsdockeruh/simple-web-service` will start a web service in port `8080` when given the argument "server". In [Exercise 1.8](/part-1/section-3#exercises-17---18) you already did an image that can be used to run the web service without any argument.

Use now the -p flag to access the contents with your browser. The output to your browser should be something like:
`{ message: "You connected to the following path: ...`
Expand Down

0 comments on commit e93c365

Please sign in to comment.