Cloud Computing - Lab 3
Cloud Computing - Lab 3
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.
http.createServer(onRequest).listen(8888);
console.log('Server has started');
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/.
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 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 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