Skip to content

Commit 6999d1a

Browse files
authored
lab2 init.sh changes (#61)
* updated init.sh script * updated lab2 readme based on init.sh changes
1 parent d7884a0 commit 6999d1a

File tree

2 files changed

+40
-93
lines changed

2 files changed

+40
-93
lines changed

labs/lab2/init.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,15 @@ sudo apt-get install -y docker.io
1010

1111
# Install Docker Compose
1212
sudo curl -L "https://github.com/docker/compose/releases/download/v2.27.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
13-
sudo chmod +x /usr/local/bin/docker-compose
13+
sudo chmod +x /usr/local/bin/docker-compose
14+
15+
# Create a new directory
16+
cd $HOME
17+
mkdir cafe
18+
19+
# Download docker compose file
20+
cd cafe
21+
wget https://raw.githubusercontent.com/nginxinc/nginx-azure-workshops/main/labs/lab2/docker-compose.yml
22+
23+
# Run docker compose to create the containers
24+
sudo docker-compose up -d

labs/lab2/readme.md

Lines changed: 28 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ NGINX aaS | Ubuntu | Docker | Windows
2020

2121
By the end of the lab you will be able to:
2222

23-
- Deploy Ubuntu VM with Docker and Docker-Compose preinstalled using Azure CLI
24-
- Run Nginx demo application containers
23+
- Deploy Ubuntu VM with Docker and Docker-Compose preinstalled and Nginx Demo containers running using Azure CLI
2524
- Configure Nginx for Azure to Load Balance Docker containers
2625
- Test and validate your lab environment
2726
- Deploy Windows VM with Azure CLI
@@ -42,7 +41,7 @@ By the end of the lab you will be able to:
4241

4342
<br/>
4443

45-
## Deploy Ubuntu VM with Docker and Docker-Compose preinstalled using Azure CLI
44+
## Deploy Ubuntu VM with Docker and Docker-Compose preinstalled and Nginx Demo containers running using Azure CLI
4645

4746
1. In your local machine open terminal and make sure you are logged onto your Azure tenant. Set the following Environment variable which points to your Resource Group:
4847

@@ -51,7 +50,11 @@ By the end of the lab you will be able to:
5150
export MY_RESOURCEGROUP=s.dutta-workshop
5251
```
5352

54-
>*Make sure your Terminal is the `nginx-azure-workshops/labs` directory for all commands during this Workshop.*
53+
1. Make sure your Terminal is the `nginx-azure-workshops/labs` directory for all commands during this Workshop.
54+
55+
```bash
56+
cd labs
57+
```
5558

5659
1. Create the Ubuntu VM that would be acting as your backend application server using below command:
5760

@@ -97,6 +100,11 @@ By the end of the lab you will be able to:
97100
- **n4a-ubuntuvmNSG:** This is your network security group resource tied to the network interface of your vm.
98101
- **n4a-ubuntuvmPublicIP:** This is your public IP resource tied to your vm.
99102

103+
The `lab2/init.sh` script will perform several task as listed below:
104+
- install docker and docker compose within the vm
105+
- download the workshop docker-compose file that would build the backend containers
106+
- Run the downloaded docker-compose file to build all the backend containers.
107+
100108
This command will also generate a SSH key file named `id_rsa` under `~/.ssh` folder if you don't have one already.
101109
102110
**SECURITY WARNING:** This new VM has SSH/port22 open to the entire Internet, and is only using an SSH Key file for security. Take appropriate steps to secure your VM if you will be using it for more than a couple hours!
@@ -116,7 +124,15 @@ By the end of the lab you will be able to:
116124
--source-address-prefix $MY_PUBLICIP
117125
```
118126
119-
1. Verify you have SSH access to the Ubuntu VM that you deployed in previous steps. Open a Terminal, and use your public IP tied to ubuntu vm, to start a new ssh session.
127+
>Success! You have an Ubuntu VM with Docker that is running Nginx Demo containers needed for future Lab exercises. Reminder: Don't forget to shutdown this VM when you are finished with it later, or set an Auto Shutdown policy using Azure Portal.
128+
129+
<br/>
130+
131+
### (Optional Section) SSH into the Ubuntu VM and test Nginx Demo containers
132+
133+
In this section, you will ssh into the Ubuntu VM that you created in previous section. You will then inspect the docker containers and look into the three Nginx `ingress-demo` containers. These containers will be your first group of `backends` that will be used for load balancing with Nginx for Azure.
134+
135+
1. Verify you have SSH access to the Ubuntu VM that you deployed in previous section. Open a Terminal, and use your public IP tied to ubuntu vm, to start a new ssh session.
120136

121137
```bash
122138
ssh azureuser@<UBUNTU_VM_PUBLICIP>
@@ -134,107 +150,29 @@ By the end of the lab you will be able to:
134150

135151
![cloudshell](media/lab2-cloudshell.png)
136152

137-
1. Within the Ubuntu VM, run below commands to validate docker and docker compose are installed as part of the `init.sh` script that you passed as one of the parameters to the `az vm create` command
153+
1. Within the Ubuntu VM, run below commands to validate docker and docker compose are installed as part of the `init.sh` script.
138154

139155
```bash
140156
docker version
141157
docker-compose version
142158
```
143159

144-
1. Test and see if Docker will run the `Hello-World` container:
145-
146-
```bash
147-
sudo docker run hello-world
148-
```
149-
150-
```bash
151-
##Sample Output##
152-
Unable to find image 'hello-world:latest' locally
153-
latest: Pulling from library/hello-world
154-
c1ec31eb5944: Pull complete
155-
Digest: sha256:53641cd209a4fecfc68e21a99871ce8c6920b2e7502df0a20671c6fccc73a7c6
156-
Status: Downloaded newer image for hello-world:latest
157-
158-
Hello from Docker!
159-
This message shows that your installation appears to be working correctly.
160-
161-
To generate this message, Docker took the following steps:
162-
1. The Docker client contacted the Docker daemon.
163-
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
164-
(amd64)
165-
3. The Docker daemon created a new container from that image which runs the
166-
executable that produces the output you are currently reading.
167-
4. The Docker daemon streamed that output to the Docker client, which sent it
168-
to your terminal.
169-
170-
To try something more ambitious, you can run an Ubuntu container with:
171-
$ docker run -it ubuntu bash
172-
173-
Share images, automate workflows, and more with a free Docker ID:
174-
https://hub.docker.com/
175-
176-
For more examples and ideas, visit:
177-
https://docs.docker.com/get-started/
178-
```
179-
180160
1. Checkout a few Docker things:
181161

182162
```bash
183163
sudo docker images
184164
```
185165

186-
```bash
187-
sudo docker ps -a
188-
```
189-
190-
You should find the hello-world image was pulled, and that the container ran and exited.
166+
You should find the `nginxinc/ingress-demo` image was pulled.
191167

192-
>Success! You have an Ubuntu VM with Docker that can run various containers needed for future Lab exercises. Reminder: Don't forget to shutdown this VM when you are finished with it later, or set an Auto Shutdown policy using Azure Portal.
193-
194-
Leave your SSH Terminal running, you will use it in the next section.
195-
196-
<br/>
197-
198-
### Deploy Nginx Demo containers
199-
200-
You will now use Docker Compose to create and deploy three Nginx `ingress-demo` containers. These will be your first group of `backends` that will be used for load balancing with Nginx for Azure.
201-
202-
1. Inspect the `lab2/docker-compose.yml` file. Notice you are pulling the `nginxinc/ingress-demo` image, and starting three containers. The three containers are configured as follows:
168+
1. Inspect the `lab2/docker-compose.yml` file. This file was pulled as part of the `init.sh` script. This docker compose file creates the three containers based on `nginxinc/ingress-demo` image, that you see running. The three containers are configured as follows:
203169

204170
Container Name | Name:port
205171
:-------------:|:------------:
206172
docker-web1 | ubuntuvm:81
207173
docker-web2 | ubuntuvm:82
208174
docker-web3 | ubuntuvm:83
209175

210-
1. On the Ubuntu VM, create a new sub-directory in the `/home/azureuser` directory, call it `cafe`.
211-
212-
```bash
213-
cd $HOME
214-
mkdir cafe
215-
```
216-
217-
1. Within the `cafe` sub-directory, you will now add `docker-compose.yml`.
218-
You can do this in two ways. You can create a new `docker-compose.yml` file and copy the contents from the `lab2/docker-compose.yml` file, into this new file on the Ubuntu VM using editor of your choice (Below example uses vi tool).
219-
220-
```bash
221-
cd cafe
222-
vi docker-compose.yml
223-
```
224-
225-
Alternatively, you can get this file by running the `wget` command as shown below:
226-
227-
```bash
228-
cd cafe
229-
wget https://raw.githubusercontent.com/nginxinc/nginx-azure-workshops/main/labs/lab2/docker-compose.yml
230-
```
231-
232-
1. Start up the three Nginx demo containers using below command. This instructs Docker to read the compose file and start the three containers:
233-
234-
```bash
235-
sudo docker-compose up -d
236-
```
237-
238176
1. Check the containers are running:
239177

240178
```bash
@@ -243,10 +181,10 @@ You will now use Docker Compose to create and deploy three Nginx `ingress-demo`
243181

244182
```bash
245183
##Sample Output##
246-
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
247-
33ca8329cece nginxinc/ingress-demo "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:82->80/tcp, :::82->80/tcp, 0.0.0.0:4432->443/tcp, :::4432->443/tcp docker-web2
248-
d3bf38f7b575 nginxinc/ingress-demo "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:83->80/tcp, :::83->80/tcp, 0.0.0.0:4433->443/tcp, :::4433->443/tcp docker-web3
249-
1982b1a4356d nginxinc/ingress-demo "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:81->80/tcp, :::81->80/tcp, 0.0.0.0:4431->443/tcp, :::4431->443/tcp docker-web1
184+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
185+
33ca8329cece nginxinc/ingress-demo "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:82->80/tcp, :::82->80/tcp, 0.0.0.0:4432->443/tcp, :::4432->443/tcp docker-web2
186+
d3bf38f7b575 nginxinc/ingress-demo "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:83->80/tcp, :::83->80/tcp, 0.0.0.0:4433->443/tcp, :::4433->443/tcp docker-web3
187+
1982b1a4356d nginxinc/ingress-demo "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:81->80/tcp, :::81->80/tcp, 0.0.0.0:4431->443/tcp, :::4431->443/tcp docker-web1
250188
```
251189

252190
Notice that each container is listening on a unique TCP port on the Docker host - Ports 81, 82, and 83 for docker-web1, docker-web2 and docker-web3, respectively.
@@ -318,8 +256,6 @@ You will now use Docker Compose to create and deploy three Nginx `ingress-demo`
318256
<p class="smaller"><span>Server Address:</span> <span><font color="green">172.18.0.4:80</font></span></p>
319257
```
320258
321-
If you able to see Responses from all THREE containers, you can continue.
322-
323259
<br/>
324260
325261
## Configure Nginx for Azure to Load Balance Docker containers

0 commit comments

Comments
 (0)