Outils pour utilisateurs

Outils du site


issue199:c_c

Ceci est une ancienne révision du document !


Now that you know how to create your own web server, I want us to look into web applications. For this we will start with Docker. Now if you know what a Snap package is, well that is basically what Docker is for web applications.

Again, we will go for the low-hanging fruit and get you started as fast as I know how. (There is a lengthy install instruction on the docker homepage, but we are taking the easy route - Thanks @fleabite08). I’m going to assume you are using Ubuntu desktop.

Installation:

Open your terminal and type:

sudo apt install docker.io -y

Once it has completed, type

sudo docker -v

OK, we have Docker, now what? Well, we need a web application. Something like Redis, but as we are starting out, let’s set our aim lower. Something everyone can appreciate and understand.

Docker has a central repository, if you will, for all these application images. Some are public and some are private. You can go look at the images available - https://hub.docker.com - and there will be instructions on how to get them. A quick word: like any public repository, anyone can publish to the docker hub. Try to eyeball official applications, that is, look for the verified publisher and checkmark.

Let us try it out:

Type:

sudo docker run docker/whalesay cowsay boo

• docker run – is the initialisation command • docker/whalesay - is the image location on docker hub. • cowsay hello – is the message you want to output in the app.

So as you can see, it is not difficult.

So what happened when you typed the command?

Docker looked to see if you already had the application, and then started pulling it from Docker hub.

Let’s try a basic command, type:

docker ps

Everyone makes mistakes. On some distros, you cannot log in as root and you will need sudo. Be sure you have sudo or root access. As my container is no longer running, I do not see it with docker ps. I need to tack on -a, to see ALL the containers. This is the thing about containers. They are usually created to do one job, then exit, but you can have applications that continue running. To stop a running container, the keyword is stop. Can you guess the command? Stopping a container requires either its name or its ID. If you look at either, you can see it is a few characters. However, you just need to type enough for it to be unique. In our case, we have only the one, so it is easy, but if you have many, you need to be very careful here. The command: sudo docker stop <the name of YOUR container>

If you were on the ball, you may have noticed in our command output from “docker ps -a” that the status says exited.

Now that our container came to life, did its job, and died again, we may be done with it. Time to free up some disk space. To remove a container, the command is rm, just like in the shell. To do this, the container needs to be stopped or exited. Type:

sudo docker rm <the name of YOUR container>

Though the container is now gone, there is still the locally cached image that you grabbed from Docker hub on your PC, making reinstallation really quick. To see what images are stored on the local machine, use the following command: sudo docker images

Just to make sure you do not accidentally delete the image with the rm command, to remove an image, there is a separate command, rmi. You need to make sure that no containers are running off an image, before you remove it.

Try it yourself.

If you get an error that it cannot find your image, simply use the ID. Remember what I said earlier of it having to be unique? In my case, I have only the one, so I can type: sudo rmi 6b and it will be removed.

Is yours gone yet?

We can grab the image again if needed, simply pull it: sudo docker pull docker/whalesay - and it will download it again, without running it.

Homework:

Grab the Ubuntu image and run it.

What happened???

We will discuss this in the next issue.

As always, if we are boring you, drop us a line at: misc@fullcirclemagazine.org

issue199/c_c.1700933820.txt.gz · Dernière modification : 2023/11/25 18:37 de auntiee