24/08/2021
CRICOS code 00025BCRICOS code 00025B
Copyright By PowCoder代写 加微信 powcoder
• Mask restrictions continue – carrying masks, wearing masks, check-in QLD
• GCP coupons redeem (check the latest announcement)
• The next Student Consultative Committee meeting will be taking place next Wednesday, 25 August.
• Students can join the mailing list by emailing
The meeting details are as follows:
Date: Wednesday, 25 August, 2021
Time: 12:00 – 1:00 pm
Room: 50-T105 and via Zoom (link will be provided to mailing list and upon request)
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Container
• What is Docker
• Basic concepts in Docker
– Containers
– Registry
– Layer architecture
• Docker Commands
• Containerisation and Dockerfile
– Dokcerfile instructions
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Microservices
• Docker Compose
• Docker Swam
• Docker Machine
• Create a Swarm
• Deploy Services to a Swarm
• Deploy a Stack to a Swarm
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Last week…
• Ubuntu base image
• MySQL RDBMS, WordPress
One-size-for-all container?
Cloud Computing
Image taken from web
• MongoDB/Redis
• Nginx or Apache HTTP Server
• Programming Language support:
Java, Python, Go, etc.
Should we have a one-size-for-all container for the project?
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Separate business logic functions
• Instead of one big program, several smaller applications
• Communicate via well defined APIs – usually HTTP
• In demand
Microservices
Cloud Computing
https://aws.amazon.com/microservices/
https://aws.amazon.com/microservices/
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Microservices are an architectural and organizational approach to software development where software is
composed of small independent services that communicate over well-defined APIs.
Microservices
Cloud Computing
https://aws.amazon.com/microservices/?nc1=h_ls
User Interface
Business Logic
Data Access
User Interface
Microservice
DB DB DB DB
Microservice
Microservice
Monolithic Architecture Microservices Architecture
https://aws.amazon.com/microservices/?nc1=h_ls
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Technological Freedom – Language independent
• Easy Deployment – Fast iterations & Reusable Code
• Agility (Small teams)
• Resilience (Fault Isolation)
• Flexible Scaling (Scalable)
• Infrastructure Overhead
– Servers and databases
• Complicated networking
Microservices – Pros and Cons
Cloud Computing
https://aws.amazon.com/microservices/?nc1=h_ls
https://aws.amazon.com/microservices/?nc1=h_ls
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Question: Should we have a One-size-for-all container for each project?
• Ubuntu base image
• MySQL RDBMS
• MongoDB/Redis
• Nginx or Apache HTTP Server
• Programming Language support: Java, Python, Go, etc.
Issues: Monolithic-like container is not scalable and chunky
Solution: containerize microservices and run multiple containers
Question Revisited
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Example: The first assignment
• Php-fpm and nginx
Question Revisited
Cloud Computing
# Build and start apps!
• docker build -> Images
• docker run a1:luo
• docker stop a1:luo
• docker rm a1:luo
# Make changes, rebuild image,
• docker build -> Images
• docker run a1:luo
What if we have another container,
e.g., mariadb?
– When to start the db container?
– If the db container unexpectedly shut down?
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Cloud Computing
• Microservices
• Docker Compose
• Docker Swam
• Docker Machine
• Create a Swarm
• Deploy Services to a Swarm
• Deploy a Stack to a Swarm
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Compose is a tool for defining and running multi-container Docker
applications.
• Use a Compose file (docker-compose.yml) to configure
application’s services.
• Use a single command to create and start all the services from the
configuration (docker-compose up).
Docker Compose
Cloud Computing
An example of docker-compose.yml
• Three-step process:
1. Define your app’s environment with a Dockerfile
2. Define the services that make up your app in docker-
compose.yml so they can be run together in an
isolated environment.
3. Lastly, run docker-compose up and Compose will
start and run your entire app.
docker-compose –f docker-compose.json up
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Two basic concepts in docker compose:
– Service: running containers (one/multiple running instances of the same
– Project: a complete business unit (consists of multiple linked containers)
• Compose is targeting at the project management and has commands for
managing the whole lifecycle of your application:
– Start, stop and rebuild services
– View the status of running services
– Stream the log output of running services
Docker Compose
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Web application in “app.py”
• Dockerfile
An Example of Docker Compose
Cloud Computing
• docker-compose.yml
• Run docker-compose up
24/08/2021
CRICOS code 00025BCRICOS code 00025B
The objectives of most of compose commands are either project (by default) or
services/containers within the project.
docker-compose [-f=
Compose commands
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
docker-compose up [options] [–scale SERVICE=NUM…] [SERVICE…]
• Builds, (re)creates, starts, and attaches to containers for a service.
• Important options:
• “-d”: keep all the containers in yaml file running in the background.
• “–build”: force to rebuild the image
• “–no-recreate”: ignore existing running containers and start all the stopped
containers.
• “–force-recreate”: force Compose to stop and recreate all containers.
• “–no-deps -d
container.
Compose commands – up
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
For all services…
docker-compose build
docker-compose down [options]
• Stops containers and removes containers, networks, volumes, and images created
For a certain service…
docker-compose run [SERVICE…]
• creates containers from images built for the services mentioned in the compose file
docker-compose start [SERVICE…]
• Starts runs any stopped containers for a service.
docker-compose stop, restart, kill, rm (un)paused
Compose commands – change state
Cloud Computing
https://docs.docker.com/compose/reference/overview/
https://docs.docker.com/compose/reference/overview/
24/08/2021
CRICOS code 00025BCRICOS code 00025B
docker-compose logs [options] [SERVICE…]
• Displays log output from services.
docker-compose images
• Lists images included in the docker-
compose.yml file.
docker-compose ps [options] [SERVICE…]
• Lists containers.
docker-compose top
• Displays the running processes.
Compose commands – check information
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Multi-service applications are defined in a configuration file
• docker-compose.yml (by default, but can use “-f” to read .yml file
with a customised file name).
• YAML is a superset of JSON.
• consists of multiple layers that are split using tab stops or spaces
• Four main components in each Compose-File:
– Compose file’s version
– Services (containers)
– Volumes (storage)
– Networks (linking)
Compose files
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Second-level definitions in “services”:
• “db” (relational database – mysql)
• “wordpress” (Free and open-source CMS – WP).
Instructions in “db“:
• “image” (or “build”):
– pulls the latest image of mysql and use it to create the container for
this service
– “build” can be used with “Dockerfile” to build the customised image
• “volumes”: mounts folder db_data (source) to /var/lib/mysql.
• “restart”: specify restart policy for containers.
• “environment”: Add environment variables.
– Boolean values (i.e. true/false, yes/no) need to be quoted (i.e.
restart: “no”).
Compose files
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Instructions in “wordpress”:
• “depends_on”: expresses dependency between services. Service
dependencies cause the following behaviours:
– docker-compose up starts services in dependency order.
E.g. “db” is started before “wordpress”.
– docker-compose up [SERVICE] automatically includes SERVICE’s
dependencies.
E.g. docker-compose up wordpress also creates and starts “db”.
– docker-compose stop stops services in dependency order.
E.g. “wordpress” is stopped before “db”.
• “ports”: exposes or maps ports
– (HOST_PORT:CONTAINER_PORT) or (CONTAINER_PORT)
E.g. “ports: 8000:80” or “ports: 80”
– Port range: “-” and protocal: “/”
E.g. “127.0.0.1:8000-8009:5000-5009” and “6000:6000/tcp”
• “networks”: defines the communication rules between containers
Compose files
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Microservices
• Docker Compose
• Docker Swam
• Docker Machine
• Create a Swarm
• Deploy Services to a Swarm
• Deploy a Stack to a Swarm
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• The portability and reproducibility of a containerised process help us
– migrate containerised applications to clouds efficiently;
– scale the containerised applications on the clouds effectively.
• How do we make docker work across multiple nodes?
– Share containers among each other
– replace failed containers automatically,
– manage the rollout of updates and reconfigurations of those containers
during their lifecycle.
Orchestration
Cloud Computing
24/08/2021
CRICOS code 00025B
• Definition: automated configuration,
management, and coordination of
computer systems, applications, and
• Tools to manage, scale, and maintain
containerised applications are called
orchestrators
– Examples: Apache Mesos, Kubernetes,
Docker Swarm, Amazon ECS.
Orchestration
Cloud Computing INFS3208
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Docker Swarm manages a cluster of Docker nodes and schedule containers
Docker Swarm
Cloud Computing
• Each node of a docker swarm is a Docker
daemon and all Docker daemons interact using
the Docker API
• Docker daemon is responsible for
• Pulling images, starting containers
• Managing volumes, networks
• The REST API provides access to the daemon
• The Docker CLI is simply making API requests
Architecture of Docker Engine
https://docs.docker.com/machine/
https://docs.docker.com/machine/
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Docker Swarm manages a cluster of Docker nodes and schedule containers
• Each node of a docker swarm is a Docker daemon and all Docker daemons
interact using the Docker API
Docker Swarm
Cloud Computing
Containers
Reschedule containers on
node failure
•maintaining cluster state
•scheduling services
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Docker Swarm manages a cluster of Docker nodes and schedule containers
• Each node of a docker swarm is a Docker daemon and all Docker daemons
interact using the Docker API
Docker Swarm
Cloud Computing
Containers
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Cluster management integrated with Docker Engine
• Decentralized Design
• Load Balancing
• Secure by Default
• Rolling Updates
Key Features of Docker Swarm
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Initialize a cluster of Docker Engines in swarm mode
• Adding nodes to swarm
• Deploying application services to the swarm
• Managing the swarm once you have everything running
Getting Started with Swarm Mode
Cloud Computing
https://docs.docker.com/engine/swarm/swarm-tutorial/
https://docs.docker.com/engine/swarm/swarm-tutorial/
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Microservices
• Docker Compose
• Docker Swam
• Docker Machine
• Create a Swarm
• Deploy Services to a Swarm
• Deploy a Stack to a Swarm
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Docker Machine allows you to provision Docker machines in a variety of environments,
• virtual machines either on local systems or on cloud providers,
• physical computers.
Docker Machine creates a Docker host, and you use the Docker Engine client as
needed to build images and create containers on the host.
Docker Machine – Docker Hosts Management
Cloud Computing
VM or physical machine VM or physical machine VM or physical machine
Docker host Docker host Docker host
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Example: Create three different machines using docker-machine create
1. Manager1 (docker-machine create –driver virtualbox manager1)
2. Worker1 (docker-machine create –driver virtualbox worker1)
3. Worker2 (docker-machine create –driver virtualbox worker2)
Docker Machine – Docker Hosts Management
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
To create a virtual machine, you supply Docker Machine with the name of the driver you
want to use.
• For a local Mac or Windows system, the driver is typically Oracle VirtualBox.
• For provisioning physical machines, a generic driver is provided.
• For cloud providers, Docker Machine supports drivers such as AWS, Microsoft Azure,
Google Compute Engine, etc.
Docker Machine – Docker Hosts Management
Cloud Computing
https://docs.docker.com/machine/drivers/gce/
https://docs.docker.com/machine/drivers/gce/
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Docker Machine – GCP
Cloud Computing
https://docs.docker.com/machine/drivers/gce/
1. Stop the vm instance and edit the vm setting
• in API access scopes select “Allow full access to all
Cloud APIs” and click in save
2. Restart the vm instance, install docker-machine
3. Then run:
https://docs.docker.com/machine/drivers/gce/
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Docker Machine – Additional Network Check
Cloud Computing
https://docs.docker.com/engine/swarm/swarm-tutorial/
The following ports must be available. On some systems, these ports are open
by default.
• TCP port 2377 for cluster management communications
• TCP and UDP port 7946 for communication among nodes
• UDP port 4789 for overlay network traffic
https://docs.docker.com/engine/swarm/swarm-tutorial/
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Microservices
• Docker Compose
• Docker Swam
• Docker Machine
• Create a Swarm
• Deploy Services to a Swarm
• Deploy a Stack to a Swarm
Cloud Computing
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Create a Swarm
Cloud Computing
https://docs.docker.com/engine/swarm/swarm-tutorial/
Make sure the Docker Engine daemon is started on the host machines.
1. Open a terminal and ssh into the machine where you want to run your
manager node. If you use Docker Machine, you can connect to it via SSH using
the following command:
https://docs.docker.com/engine/swarm/swarm-tutorial/
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Create a Swarm
Cloud Computing
https://docs.docker.com/engine/swarm/swarm-tutorial/
2. Run the following command to create a new swarm on the manager node:
https://docs.docker.com/engine/swarm/swarm-tutorial/
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Create a Swarm
Cloud Computing
https://docs.docker.com/engine/swarm/swarm-tutorial/
3. Jump to a worker node and join to the swarm:
Change to the internal IP of the manager node
https://docs.docker.com/engine/swarm/swarm-tutorial/
24/08/2021
CRICOS code 00025BCRICOS code 00025B
Manage Nodes in a Swarm
Cloud Computing
https://docs.docker.com/engine/swarm/manage-nodes/
docker node ls
• Displays view a list of nodes in the swarm
docker node promote/depromote [HOSTNAME]
• Change the role of node e.g., manager to worker
docker node rm [HOSTNAME]
• Delete a node
https://docs.docker.com/engine/swarm/manage-nodes/
24/08/2021
CRICOS code 00025BCRICOS code 00025B
• Microservices
• Docker Compose
• Docker Swam
• Docker Machine
• Create a Swarm
• Deploy Services to a Swarm
• Deploy a Stack to a Swarm
Cloud Computing
24/08/2021
CRICOS code 00025B
• Service: specified by its desired state: which image, how
many instances
• The leader uses different subsystems to break down
services in to tasks.
• Task: corresponds to a specific container, assigned to a
specific node
Deploy Services to a Swarm
Cloud Computing INFS3208
https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/
https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/
24/08/2021
CRICOS code 00025B
Deploy Services to a Swarm
Cloud Computing INFS3208
https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/
https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/
24/08/2021
CRICOS code 00025B
Deploy Services to a Swarm
Cloud Computing INFS3208
https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/
https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/
24/08/2021
CRICOS code 00025B
Deploy Services to a Swarm
Cloud Computing INFS3208
• Open a terminal and ssh into the machine where you run your manager node
• specify a command that the service’s containers should run, by adding it after the image name. The
below example starts a service called helloworld which uses an alpine image and runs the command
ping docker.com:
24/08/2021
CRICOS code 00025B
Deploy Services to a Swarm
Cloud Computing INFS3208
• Run docker service ps helloworld to see which nodes are running the service:
• Run docker ps on the node where the task is running to see details about the containers
24/08/2021
CRICOS code 00025B
Scale Services in a Swarm
Cloud Computing INFS3208
• Run the following command to change the desired scale of the service running in the swarm
docker service scale
SERVICE=REPLICAS
[SERVICE=REPLICAS…]
How to scale down the
service helloworld?
24/08/2021
CRICOS code 00025B
Rolling Updates
Cloud Computing INFS3208
• Run the following command to change the desired scale of the service running in the swarm
24/08/2021
CRICOS code 00025B
Publish Ports
Cloud Computing INFS3208
When you create a swarm service, you can publish that service’s ports to hosts
outside the swarm in two ways:
• Routing Mesh: swarm makes the service accessible at the target port on
every node
• Publish a service task’s port directly on the swarm node.
24/08/2021
CRICOS code 00025B
Routing Mesh
Cloud Computing INFS3208
• Routing Mesh: swarm makes th
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com