Skip to content

Commit 0773e94

Browse files
authored
Merge pull request #222213 from asudbring/cni-docker-howto
New article for creating a standalone docker linux host with the Azure CNI plugin
2 parents 753d69d + 4e3dbc5 commit 0773e94

File tree

3 files changed

+254
-0
lines changed

3 files changed

+254
-0
lines changed
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
---
2+
title: Deploy container networking for a stand-alone Linux Docker host
3+
titleSuffix: Azure Virtual Network
4+
description: Learn how to deploy the Azure CNI plug-in to enable container virtual network connectivity for a standalone Linux Docker host.
5+
author: asudbring
6+
ms.author: allensu
7+
ms.service: virtual-network
8+
ms.topic: how-to
9+
ms.date: 12/22/2022
10+
ms.custom: template-how-to
11+
---
12+
13+
# Deploy container networking for a stand-alone Linux Docker host
14+
15+
The Azure CNI plugin enables per container/pod networking for stand-alone docker hosts and Kubernetes clusters. In this article, you'll learn how to install and configure the CNI plugin for a standalone Linux Docker host.
16+
17+
## Prerequisites
18+
19+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
20+
21+
## Create virtual network
22+
23+
A virtual network contains the virtual machine used in this article. In this section, you'll create a virtual network and subnet. You'll enable Azure Bastion during the virtual network deployment. The Azure Bastion host is used to securely connect to the virtual machine to complete the steps in this article.
24+
25+
1. Sign in to the [Azure portal](https://portal.azure.com).
26+
27+
2. In the search box at the top of the portal, enter **Virtual network**. Select **Virtual networks** in the search results.
28+
29+
3. Select **+ Create**.
30+
31+
4. Enter or select the following information in the **Basics** tab of **Create virtual network**:
32+
33+
| Setting | Value |
34+
| ------- | ----- |
35+
| **Project details** | |
36+
| Subscription | Select your subscription. |
37+
| Resource group | Select **Create new**. </br> Enter **myResourceGroup** in **Name**. </br> Select **OK**. |
38+
| **Instance details** | |
39+
| Name | Enter **myVNet**. |
40+
| Region | Select a region. |
41+
42+
5. Select **Next: IP Addresses**.
43+
44+
6. In **IPv4 address space**, enter **10.1.0.0/16**.
45+
46+
7. Select **+ Add subnet**.
47+
48+
8. Enter or select the following information:
49+
50+
| Setting | Value |
51+
| ------- | ----- |
52+
| Subnet name | Enter **mySubnet**. |
53+
| Subnet address range | Enter **10.1.0.0/24**. |
54+
55+
9. Select **Add**.
56+
57+
10. Select **Next: Security**.
58+
59+
11. Select **Enable** in **BastionHost**.
60+
61+
12. Enter or select the following information:
62+
63+
| Setting | Value |
64+
| ------- | ----- |
65+
| Bastion name | Enter **myBastion**. |
66+
| AzureBastionSubnet address space | Enter **10.1.1.0/26**. |
67+
| Public IP address | Select **Create new**. </br> Enter **myBastionIP** in **Name**. </br> Select **OK**. |
68+
69+
13. Select **Review + create**.
70+
71+
14. Select **Create**.
72+
73+
It can take a few minutes for the Bastion host to deploy. You can continue with the steps while the Bastion host is deploying.
74+
75+
## Create virtual machine
76+
77+
In this section, you'll create an Ubuntu virtual machine for the stand-alone Docker host. Ubuntu is used for the example in this article. The CNI plug-in supports Windows and other Linux distributions.
78+
79+
1. In the search box at the top of the portal, enter **Virtual machine**. Select **Virtual machines** in the search results.
80+
81+
2. Select **+ Create** > **Azure virtual machine**.
82+
83+
3. Enter or select the following information in the **Basics** tab of **Create a virtual machine**:
84+
85+
| Setting | Value |
86+
| ------- | ----- |
87+
| **Project details** | |
88+
| Subscription | Select your subscription. |
89+
| Resource group | Select **myResourceGroup**. |
90+
| **Instance details** | |
91+
| Virtual machine name | Enter **myVM**. |
92+
| Region | Select a region. |
93+
| Availability options | Select **No infrastructure required**. |
94+
| Security type | Select **Standard**. |
95+
| Image | Select **Ubuntu Server 20.04 LTS -x64 Gen2**. |
96+
| VM architecture | Leave the default of **x64**. |
97+
| Run with Azure Spot discount | Leave the default of unchecked. |
98+
| Size | Select a size. |
99+
| **Administrator account** | |
100+
| Authentication type | Select **Password**. |
101+
| Username | Enter a username. |
102+
| Password | Enter a password. |
103+
| Confirm password | Reenter password. |
104+
| **Inbound port rules** | |
105+
| Public inbound ports | Select **None**. |
106+
107+
4. Select **Next: Disks**, then **Next: Networking**.
108+
109+
5. Enter or select the following information in the **Networking** tab:
110+
111+
| Setting | Value |
112+
| ------- | ----- |
113+
| **Network interface** | |
114+
| Virtual network | Select **myVNet**. |
115+
| Subnet | Select **mySubnet (10.1.0.0/24)**. |
116+
| Public IP | Select **None**. |
117+
118+
6. Select **Review + create**.
119+
120+
7. Select **Create**
121+
122+
## Add IP configuration
123+
124+
The Azure CNI plugin allocates IP addresses to containers based on a pool of IP addresses you create on the virtual network interface of the virtual machine. For every container on the host, an IP configuration must exist on the virtual network interface. If the number of containers on the server outnumber the IP configurations on the virtual network interface, the container will start but won't have an IP address.
125+
126+
In this section, you'll add an IP configuration to the virtual network interface of the virtual machine you created previously.
127+
128+
1. In the search box at the top of the portal, enter **Virtual machine**. Select **Virtual machines** in the search results.
129+
130+
2. Select **myVM**.
131+
132+
3. In **Settings**, select **Networking**.
133+
134+
4. Select the name of the network interface next to **Network Interface:**. The network interface is named **myvm** with a random number. In this example, it's **myvm27**.
135+
136+
5. In **Settings** of the network interface, select **IP configurations**.
137+
138+
6. in **IP configurations**, select **ipconfig1** in **Name**.
139+
140+
7. In the **ipconfig1** settings, change the assignment of the private IP address from **Dynamic** to **Static**.
141+
142+
8. Select **Save**.
143+
144+
9. Return to **IP configurations**.
145+
146+
10. Select **+ Add**.
147+
148+
11. Enter or select the following information for **Add IP configuration**:
149+
150+
| Setting | Value |
151+
| ------- | ----- |
152+
| Name | Enter **ipconfig2**. |
153+
| **Private IP address settings** | |
154+
| Allocation | Select **Static**. |
155+
| IP address | Enter **10.1.0.5**. |
156+
157+
12. Select **OK**.
158+
159+
13. Verify **ipconfig2** has been added as a secondary IP configuration.
160+
161+
Repeat steps 1 through 13 to add as many configurations as containers you wish to deploy on the container host.
162+
163+
## Install Docker
164+
165+
The Docker container engine must be installed and configured on the virtual machine you created previously.
166+
167+
For install instructions for Docker on an Ubuntu container host, see [Install Docker Engine on Ubuntu](https://docs.docker.com/engine/install/ubuntu/).
168+
169+
After Docker is installed on the virtual machine, follow the instructions for the Linux post install. For instructions on the Linux post install, see [Docker Engine post-installation steps](https://docs.docker.com/engine/install/linux-postinstall/).
170+
171+
After Docker is installed on your virtual machine, continue with the steps in this article.
172+
173+
## Install CNI plugin and create a test container
174+
175+
The Azure CNI plugin is maintained as a GitHub project and is available for download from the project's GitHub page. For this article, you'll use **`git`** within the virtual machine to clone the repository for the plugin and then install and configure the plugin.
176+
177+
For more information about the Azure CNI plugin, see [Microsoft Azure Container Networking](https://github.com/Azure/azure-container-networking).
178+
179+
1. In the search box at the top of the portal, enter **Virtual machine**. Select **Virtual machines** in the search results.
180+
181+
2. Select **myVM**.
182+
183+
3. In the **Overview** of **myVM**, select **Connect** then **Bastion**.
184+
185+
4. Enter the username and password you created when you deployed the virtual machine in the previous steps.
186+
187+
5. Select **Connect**.
188+
189+
6. The application **jq** is required for the install script for the CNI plugin, use the following example to install the application:
190+
191+
```bash
192+
sudo apt-get update
193+
sudo apt-get install jq
194+
```
195+
7. Next, you'll clone the repository for the CNI plugin. Use the following example to clone the repository:
196+
197+
```bash
198+
git clone https://github.com/Azure/azure-container-networking.git
199+
```
200+
201+
8. Configure permissions and install the CNI plugin. The install script command requires a version number for the CNI plugin. At the time of the writing of this article, the newest version is **`v1.4.39`**. To obtain the latest version number of the plugin or previous versions, see [Releases](https://github.com/Azure/azure-container-networking/releases).
202+
203+
```bash
204+
cd azure-container-networking
205+
cd scripts
206+
chmod u+x install-cni-plugin.sh
207+
sudo ./install-cni-plugin.sh v1.4.39
208+
chmod u+x docker-run.sh
209+
```
210+
211+
9. To start a container with the CNI plugin, you must use a special script that comes with the plugin to create and start the container. The following example will create an Alpine container with the CNI plugin script:
212+
213+
```bash
214+
sudo ./docker-run.sh vnetdocker1 default alpine
215+
```
216+
217+
10. To verify that the container received the IP address you previously configured, connect to the container and view the IP:
218+
219+
```bash
220+
sudo docker exec -it vnetdocker1 /bin/sh
221+
```
222+
223+
11. Use the **`ifconfig`** command in the following example to verify the IP address was assigned to the container:
224+
225+
```bash
226+
ifconfig
227+
```
228+
:::image type="content" source="./media/deploy-container-networking-docker-linux/ifconfig-output.png" alt-text="Screenshot of ifconfig output in Bash prompt of test container.":::
229+
230+
## Clean up resources
231+
232+
If you're not going to continue to use this application, delete the virtual network and virtual machine with the following steps:
233+
234+
1. In the search box at the top of the portal, enter **Resource group**. Select **Resource groups** in the search results.
235+
236+
2. Select **myResourceGroup**.
237+
238+
3. In the **Overview** of **myResourceGroup**, select **Delete resource group**.
239+
240+
4. In **TYPE THE RESOURCE GROUP NAME:**, enter **myResourceGroup**.
241+
242+
5. Select **Delete**.
243+
244+
## Next steps
245+
246+
In this article, you learned how to install the Azure CNI plugin and create a test container.
247+
248+
For more information about Azure container networking and Azure Kubernetes service, see:
249+
250+
- [Deploy the Azure Virtual Network container network interface plug-in](deploy-container-networking.md)
251+
252+
- [What is Azure Kubernetes Service?](/azure/aks/intro-kubernetes)
210 KB
Loading

articles/virtual-network/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@
198198
href: /azure/architecture/reference-architectures/hybrid-networking/expressroute-vpn-failover?toc=/azure/virtual-network/toc.json
199199
- name: Configure Virtual network TAP
200200
href: tutorial-tap-virtual-network-cli.md
201+
- name: Standalone docker host container networking - Linux
202+
href: deploy-container-networking-docker-linux.md
201203
- name: Deploy Container networking
202204
href: deploy-container-networking.md
203205
- name: Security

0 commit comments

Comments
 (0)