From d37781f3789dc29fc01384b7a9cce0728dfd5e57 Mon Sep 17 00:00:00 2001 From: Arnaud Morin Date: Sat, 8 Jan 2022 20:56:26 +0100 Subject: [PATCH] docker Signed-off-by: Arnaud Morin --- ansible/training/README.md | 6 ++ ansible/training/lessons/1-intro.md | 4 +- ansible/training/userdata/ansible101.sh | 4 +- docker/training/lessons/1-docker101.md | 122 ++++++++++++++++++++++++ index.html | 32 +++++++ 5 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 docker/training/lessons/1-docker101.md create mode 100644 index.html diff --git a/ansible/training/README.md b/ansible/training/README.md index e9faf69..17ea8d5 100644 --- a/ansible/training/README.md +++ b/ansible/training/README.md @@ -2,3 +2,9 @@ Ansible Simple Training Start with [lessons/](lessons/) + +ssh to your machine +install ansible +check ansible inventory +few ad-hoc commands + diff --git a/ansible/training/lessons/1-intro.md b/ansible/training/lessons/1-intro.md index 1c2fb58..98460df 100644 --- a/ansible/training/lessons/1-intro.md +++ b/ansible/training/lessons/1-intro.md @@ -17,7 +17,7 @@ During these lessons, you will be ask to use ansible to configure both `localhos Install ansible on `localhost` ``` -apt-get install ansible +# Figure out the command to do that ``` # First use @@ -67,7 +67,7 @@ ansible101 Q: what command can you use to get the IP of your machine? ## Ad-hoc setup -The `setup`module is a builtin module that collects data (also known as `facts`) on hosts. +The `setup` module is a builtin module that collects data (also known as `facts`) on hosts. These data can then be used as variables in your future playbooks (we will see that later). ``` diff --git a/ansible/training/userdata/ansible101.sh b/ansible/training/userdata/ansible101.sh index 4255891..43ab5d2 100644 --- a/ansible/training/userdata/ansible101.sh +++ b/ansible/training/userdata/ansible101.sh @@ -55,11 +55,11 @@ apt-get install -y docker-ce docker-ce-cli containerd.io title.print "Clone ansible-training" cd /root/ -git clone https://github.com/arnaudmorin/ansible-training.git +git clone https://github.com/arnaudmorin/trainings.git title.print "Building docker image 'demo'" -cd /root/ansible-training/docker +cd /root/trainings/ansible/training/docker docker build -t demo . #NOTE(arnaud) commented because this is something I want the student to do diff --git a/docker/training/lessons/1-docker101.md b/docker/training/lessons/1-docker101.md new file mode 100644 index 0000000..7cb5f59 --- /dev/null +++ b/docker/training/lessons/1-docker101.md @@ -0,0 +1,122 @@ +# Check your docker installation + +Run the hello-world docker container to check if everything is fine. + +``` +docker run hello-world +``` + +# Using `debian` docker +You will now use the `debian` image. + +So first, pull it from the docker hub + +``` +# Q: what command are you going to use to download locally the debian image? +your command +``` + +List the images + +``` +docker images +... +debian latest 6f4986d78878 2 weeks ago 124MB +... +``` + +Run your first docker image + +``` +docker run debian +``` + +Wait, nothing happened! Is that a bug? Well, no. Behind the scenes, a lot of stuff happened. + +When you call `run`, the Docker client finds the image (busybox in this case), loads up the container and then runs a command in that container. + +When we run `docker run debian`, we didn't provide any command, so the container booted up, ran an empty command and then exited. +Well, yeah - kind of a bummer. Let's try something more exciting. + +``` +docker run debian echo "hello from debian!" +``` +Nice - finally we see some output. +In this case, the Docker client dutifully ran the `echo` command in our `debian` container and then exited it. + +Ok, now it's time to see the `docker ps` command. +The `docker ps` command shows you all containers that are currently running: +``` +docker ps +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +f9c03ce13b09 demo "/usr/sbin/sshd -D" 32 minutes ago Up 32 minutes 127.0.0.2:8080->8080/tcp, 127.0.0.2:2222->22/tcp demo +``` +So you see only one container running, named `demo`. +This is not your `debian` container, but the container used in the previous lesson. +Why the `debian` is not visible? Because it's not running anymore! + +Q: what command can we use to retrieve all containers, including the stopped ones? + +You're probably wondering if there is a way to run more than just one command in a container. Let's try that now: + +``` +docker run -it debian bash +/ # ls +bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var +``` + +Running the `run` command with the `-it` flags attaches us to an interactive tty in the container. Now we can run as many commands in the container as we want. Take some time to run your favorite commands. + +It's now time to clean some of the old stopped containers to avoid filling your system with dead containers: +``` +docker ps -a +# grab the ID of the containers you want to clean +docker rm xxyy +``` + +Q: which parameter to `docker run` could we pass to automate the removal of the container after the execution? + +# Clean your environment +Before continuing this training, destroy all running containers using `docker stop` and `docker rm`. Destroy also the `demo` container from previous lesson, we don't need it anymore. + +# Real application +It's now time to deploy a real application. +Once again, you will deploy the `demo-flask` application, but this time, by building a docker image of this application instead of installing it using `ansible`. + +Start by cloning the app: +``` +git clone https://github.com/arnaudmorin/demo-flask.git +cd demo-flask +``` + +Take a look at the `Dockerfile`: +``` +vim Dockerfile +# to exit vim: :q +``` +A [Dockerfile](https://docs.docker.com/engine/reference/builder/) is a simple text file that contains a list of commands that the Docker client calls while creating an image. It's a simple way to automate the image creation process. + +There are a lot of different [commands](https://docs.docker.com/engine/reference/builder/#from) you can use in a `Dockerfile`. + +Q: try to describe all the commands you see in this `Dockerfile`. + +Close the `Dockerfile`. +It's now time to build our image. The `docker build` command does the heavy-lifting of creating a Docker image from a `Dockerfile`: + +``` +docker build -t yourname/demo-flask . +``` + + +Start now a container from your image: +``` +docker run yourname/demo-flask +``` +This will start a container with the demo-flask, but the app will not be accessible from outside. + +You remember that you installed a `nginx` proxy to access the previous `demo` container? + +Q: find the good `docker run` command to run your container in background and expose the port locally so the `nginx` proxy reach your application. + +Congrats, you're done with docker101! + diff --git a/index.html b/index.html new file mode 100644 index 0000000..4b6c20e --- /dev/null +++ b/index.html @@ -0,0 +1,32 @@ + + + + + + + + Trainings + + + + + +

DevOps

+

Cours

+ +

Ansible

+

Cours

+

TP

+ +

Cloud et OpenStack

+

Cours

+ +

Docker

+

Cours

+

TP

+ +

Kubernetes

+

Kubernetes

+

TP

+ +