Optimizing resources in the best possible way allows the computer to perform better. One of the ways to do it is by using virtual machines, which allow testing and generating content without the need to occupy the entire operating system.
Taking a step forward the Linux developer community has looked for the way run applications virtually using containers, which only load the core of the application that ends up creating reduced spaces in the operating system and consuming very few resources.
One of the virtual projects that has become known in recent years is Docker. You may have heard him name it somewhere, but you don’t know much about him. That is our mission in today’s course, to teach you in detail how these containers work, how they work, how to install them and how to create them.
What is Docker and what are these “containers” for in Linux?
Docker is a platform used by software developers in order to package applications in containers, making them less heavy, having the assurance that once they are going to run on any computer they will do so without any inconvenience. In that package There are the elements necessary for the tool to work on all operating systems.
The application stored in the container can be run portable even if the operating system does not have some features that are included in the package. And another advantage it has is that the computer’s resource consumption is very low, which guarantees its stability. What’s more, containers serve to save PC space and avoid contagion in case a virus or malware is dragged.
How do Linux LXC containers work and how are they different from a virtual machine?
To save resource usage, containers load only items necessary for the application to run in the kernel of the operating system. To cite one case, they could require only 20 percent of RAM and leave the rest free for any other work. In addition, the weight of containerized apps is measured in megabytes, which allows its transfer easily while in virtual machines we speak of gigabytes.
Requiring to install an additional operating system so they use more resources. Another difference is the creation period, the containers are ready in minutes while the virtual machine takes longer to run and configure. On the subject of security, virtual machines they are more secure by having their own operating system installed, the containers share the already loaded kernel.
What kind of files and documents can be kept in a Docker container?
Containers are saved as uploaded images with a configuration previous, in which I know contain the libraries, repositories and dependencies necessary to run the application. The success has been so much that large IT companies have implemented it to streamline their operations. In the end, the images that are created are in the form of layers that contain all the files entered in the container that go in three types: volumes, bind mounts, and tmpfs.
Learn step by step how to install Docker on your computer with Linux operating system
In most distros the process is the same, although there are different ways of doing it using binaries, source code or through commands, which is the option we have chosen for this course.
First, we install the system updates, entering the following line:
sudo apt update y luego sudo apt upgrade
We add some packages necessary for operation with these commands:
To get the domain and the client, we execute the following command:
sudo curl -fsSL https://get.docker.com/ | sh
Then we start the domain that will allow us to activate the service, in this case, we are going to use the following codes:
sudo systemctl enable docker
sudo systemctl start docker
To verify that the installation has gone well, we do it with the following command:
sudo systemctl status docker
Yes does not throw any error, it means that we can use it with confidence.
We show you the steps you must follow to create your first container in Linux without errors
For a container to work without errors, you need to include dependencies, libraries, and certain tools that are part of the operating system. There are a lot of commands that you will need to work, but just by executing Docker in the terminal you will meet them all.
To create the container we use this command:
docker run -i -t ubuntu /bin/echo Prueba contenedor
- The command will use a computer image and if it does not find it, it will proceed to download it.
- After creating it, assign your space and an interface that will make it possible guest / host communication.
- When you complete the process, the phrase “Test” container that we placed when creating it.
Now, there are other commands that you can use to see the development and execution of the container you just created, some examples are as follows:
-
All the images you have available, you get them with this command:
docker images
-
If you want to tear off one of the containers that you have created, use this code:
docker start -a <pon-la-ID-del-container>
-
Stopping the container is very easy, you just need to enter this:
docker stop <pon-la-ID-del-container>
Although containers have been around for a long time, Docker popularized their use in 2013, allowing developers to simplify the delivery of their packages. Secondly, For new programmers, Docker offers a clean and friendly environment, Furthermore, as it is open source, it allows you to choose the functionalities that will be used in your projects. And although there are other alternatives, the support offered by the community and its constant growth make it the best option.