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
Dockerfiles allow us to build our own images containing any software we need. However, it is important to ensure that our Dockerfiles are built to produce small, efficient images that do not contain unnecessary data. In this lesson, we will briefly discuss some general tips for creating efficient images. We will also demonstrate how to use multi-stage builds to significantly decrease image size in certain situations.
Containers present unique challenges when it comes to networking. Luckily, Docker includes multiple built-in solutions to these networking challenges. Docker implements container networking using a framework called the Container Networking Model. In this lesson, we will discuss the Container Networking Model and offer some high-level examples of some of the model's implementations.
2
+
3
+
Relevant Documentation
4
+
https://success.docker.com/article/networking/
5
+
6
+
Docker provides multiple implementations of the Container Networking Model in the form of network drivers.
Create two containers and demonstrate communication between them using the host network driver. The ip add commands also demonstrate that the container is using the host's eth0 network interface directly.
16
+
17
+
18
+
docker run -d --net host --name host_busybox radial/busyboxplus:curl sleep 3600
19
+
docker run -d --net host --name host_nginx nginx
20
+
ip add | grep eth0
21
+
docker exec host_busybox ip add | grep eth0
22
+
docker exec host_busybox curl localhost:80
23
+
curl localhost:80
24
+
25
+
Bridge
26
+
27
+
Create two containers and demonstrate that they can communicate using a custom bridge network. The ip link command can be used to explore the Linux bridge interfaces created by the bridge network driver.
Bridge networks facilitate communication between Docker containers on the same host. In this lesson, we will explore bridge networks in a little more detail. We will discuss the commands needed to create and use bridge networks. We will also examine Docker's embedded DNS, and how to use it to communicate with containers using container names and network aliases. We will also talk about some commands that can be used to manage existing networks on a Docker host.
2
+
3
+
Relevant Documentation
4
+
https://docs.docker.com/network/bridge/
5
+
Lesson Reference
6
+
Create a bridge network and demonstrate that two containers can communicate using the network.
7
+
8
+
docker network create my-net
9
+
docker run -d --name my-net-busybox --network my-net radial/busyboxplus:curl sleep 3600
10
+
docker run -d --name my-net-nginx nginx
11
+
docker network connect my-net my-net-nginx
12
+
docker exec my-net-busybox curl my-net-nginx:80
13
+
Create a container with a network alias and communicate with it from another container using both the name and the alias.
14
+
15
+
docker run -d --name my-net-nginx2 --network my-net --network-alias my-nginx-alias nginx
16
+
docker exec my-net-busybox curl my-net-nginx2:80
17
+
docker exec my-net-busybox curl my-nginx-alias:80
18
+
Create a container and provide a network alias with the docker network connect command.
The ENTRYPOINT specifies a command that will always be executed when the container starts. The CMD specifies arguments that will be fed to the ENTRYPOINT.\
41
+
\
42
+
\
43
+
\
44
+
\
45
+
\pard\pardeftab720\sl340\sa300\partightenfactor0
46
+
47
+
\f2\fs30\cf2\cb1 Both CMD and ENTRYPOINT instructions define what command gets executed when running a container. There are few rules that describe their co-operation.\
0 commit comments