Twisted in Docker
Docker is often used in micro-services architectures. Those are based on different components communicating over a network. Twisted, with its native support for several networking paradigms, is often a good fit for Docker-based architectures.
- PDF / 224,482 Bytes
- 22 Pages / 504 x 720 pts Page_size
- 74 Downloads / 191 Views
Twisted in Docker Docker is often used in micro-services architectures. Those are based on different components communicating over a network. Twisted, with its native support for several networking paradigms, is often a good fit for Docker-based architectures. Docker, and containers in general, are new. Both the tooling and the consensus on how to use the tooling are evolving fast. We are giving here the foundations on how to use Docker, so we can build the understanding of how to use Twisted in Docker on top of it. Note that Docker is a Linux-based technology. Though other operating systems have similar facilities, Docker is built on taking advantage of specific Linux-kernel facilities. Docker for Windows does have the ability to run “Windows Containers,” but this is beyond the scope of this chapter. Docker for Mac and Docker for Windows use a Virtual Machine running Linux, and have just enough integration with the host OS (OS X and Windows, respectively) to make the interaction seamless. However, it is important to remember that a Docker container is always running on a Linux kernel, even when running it on a Mac or Windows laptop.
Intro to Docker Because Docker is both new and popular, several distinct things are called “Docker.” Understanding exactly what Docker is itself is nontrivial. We try to break “Docker” here into distinct concepts. Note that each of these is often referred to as “Docker,” as well as the whole comprising them.
Containers Containers are processes that are run with more isolation than is possible in traditional UNIX processes. 157
© Mark Williams, Cory Benfield, Brian Warner, Moshe Zadka, Dustin Mitchell, Kevin Samuel, Pierre Tardy 2019 M. Williams et al., Expert Twisted, https://doi.org/10.1007/978-1-4842-3742-7_4
Chapter 4
Twisted in Docker
In a container, the only processes visible are those started by the root process of the container that appears as process ID 1 inside the container. Note that this is optional: a container can share the host’s process IDs. Using the Docker command line, this is done with the argument --pid host. Likewise, containers will have their own network address. This means processes inside the container can listen on a given port, without coordinating with the host or other running containers. Again, a container can be run with a special argument, --net host, in order to share the host network namespace. Finally, each container has its own filesystem. For example, this means we can install different Pythons in different containers without any concerns – or even conflicting Python packages. Sharing the host filesystem directly is tricky. However, we can use Docker’s “volume mount” option. The volume mount option asks to make a directory from the host accessible (“mount”) inside the container. The syntax for the option is to separate the directory from the host (on the left) and the directory it will be “mounted into” in the container (on the right) with a colon. Thus, running Docker with --volume /:/from-host will make all the host’s files accessible. N
Data Loading...