Hands-On Labs
Both labs run on a cloud VM so that the published port is reachable over the internet.
Provisioning the instance
- Open the EC2 console and select your region.
- Launch an instance; give it a name.
- Choose Ubuntu Server 20.04 LTS (or a current LTS) as the AMI.
- Choose a
t2.smallinstance type. - Create a new key pair and download it. Keep the
.pemfile private — it is the only copy. - Under network settings, keep port 22 for SSH and add an inbound rule for the application port (HTTP/80 for the first lab, custom TCP/3000 for the second).
- Launch, then connect using EC2 Instance Connect or SSH.
Install Docker using the Ubuntu steps given earlier, then refresh the shell so group membership applies.
Lab 1 — Build and run a hello-world image
sudo chown ubuntu:ubuntu -R /opt
cd /opt
docker images
docker run --rm busybox:latest /bin/echo "Hello world"
# fetch a prepared Dockerfile, build it, and run it
wget <dockerfile-url> -O Dockerfile
docker build -t helloworld .
docker run -d -p 80:8080 helloworld
docker ps -a
docker rm -f <container-id>
docker rmi <image-id>
Note the mapping -p 80:8080: the application listens on 8080 inside the container, published on
port 80 of the host, which is the port opened in the security group.
Lab 2 — Containerise a React application
docker version
sudo chown ubuntu:ubuntu -R /opt
cd /opt
git clone https://github.com/cwackerfuss/react-wordle.git
cd react-wordle
# -f names a Dockerfile that is not at the context root
docker build -t reactle:dev -f docker/Dockerfile .
docker run -d -p 3000:3000 --name reactle-dev reactle:dev
Browse to the instance's public IP on port 3000. This lab is worth doing because it uses -f to
build from a Dockerfile held in a subdirectory while keeping the repository root as the build
context — a very common real-world arrangement.