0% found this document useful (0 votes)
33 views

Cloud Computing - Lab 3

This document provides instructions for three tasks related to creating and networking Docker containers. Task 1 involves creating a Node.js web server container that returns the current date and time. Task 2 involves reading Docker networking documentation. Task 3 involves creating a user-defined bridge network with the Task 1 container and at least two additional containers that access the Task 1 container every 2 seconds, optionally using Docker Compose. Tips for common Docker commands are also provided.

Uploaded by

Gigi Beton
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Cloud Computing - Lab 3

This document provides instructions for three tasks related to creating and networking Docker containers. Task 1 involves creating a Node.js web server container that returns the current date and time. Task 2 involves reading Docker networking documentation. Task 3 involves creating a user-defined bridge network with the Task 1 container and at least two additional containers that access the Task 1 container every 2 seconds, optionally using Docker Compose. Tips for common Docker commands are also provided.

Uploaded by

Gigi Beton
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Cloud Computing

3 rd laboratory

Tasks
1.
Create a nodeJS web server that returns the current datetime. There will be an app.js with the code
that follows, and a Dockerfile that starts from the node:current-slim image, copies the app.js file,
exposes the port 8888 and executes the command node app.js.

The code for the app.js file:


var http = require('http')
var url = require('url')

http.createServer(onRequest).listen(8888);
console.log('Server has started');

function onRequest(request, response){


var pathName = url.parse(request.url).pathname
console.log('Request from ip' +
request.connection.remoteAddress + ' - pathname: ' + pathName);
response.writeHead(200);
response.write(new Date().toISOString());
response.end();
}
Run the container by forwarding port 8888 from the container to port 8000 from the host with the--
publish option. Test in the browser the address localhost:8000 and checkout the container logs.

2.
Read the Networking overview - https://docs.docker.com/network/.

Read and test the examples from Use bridge networks - https://docs.docker.com/network/bridge/.

Read and test the Networking with standalone containers tutorial -


https://docs.docker.com/network/network-tutorial-standalone/.

3.
Create a user-defined bridge network with the container from task 1 and at least two more
containers, which access the server from task 1 (by means of the IP or container name) every 2
seconds. The containers that access the server can use the curl command or any other means of
accessing the server url.

Bonus: use Docker compose - https://docs.docker.com/compose/ - to create and start all the
services from a single YAML configuration file.
Tips & Ticks
Getting started with containers
docker image build -t imageName .

docker run --publish hostPort:containerPort --detach --name containerName imageName

docker logs containerName

Other Docker commands


docker run = (docker create) + (docker start -a)

docker create – creates a container from the named image and outputs the created container id

docker start -a – is used to start the container with that id; the -a option causes the terminal to
attach so that the container runs in the foreground

docker container ls –all - shows all containers (including the ones that are not currently running)

docker run -dit --name alpine1 alpine ash – runs the alpine image with Alpine’s default shell (ash,
which is similar to bash); -dit flags mean to start the container detached (in the background),
interactive (with the ability to type into it), and with a TTY (so you can see the input and output)

docker attach alpine1 – connects to the alpine1 container – now you can execute commands on that
container; to detach press: CTRL + p, CTRL + q.

docker rm nameOrContainerId – removes the specified container

Configure your own bridge network for multiple containers


Let’s assume you have an image representing a socket server called my_server_image and an image
representing a socket client called my_client_image.

docker network create my_network – creates the network named my_network

docker run --network-alias my_server --network my_network -it my_server_image – runs the
server container; the my_server network-alias is the address of the server (on the client, use
my_server instead of localhost)

docker run --network my_network -it my_client_image – runs the client container

You might also like