Virtualization archivos » Aprende IT All the latest news about IT Mon, 29 May 2023 16:37:55 +0000 en-US hourly 1 https://aprendeit.com/wp-content/uploads/2020/02/LOGO-CORTO-100x100.png Virtualization archivos » Aprende IT 32 32 Resource Management in Virtualized Environments: Techniques and Best Practices https://aprendeit.com/en/resource-management-in-virtualized-environments-techniques-and-best-practices/ https://aprendeit.com/en/resource-management-in-virtualized-environments-techniques-and-best-practices/#respond Mon, 29 May 2023 16:33:56 +0000 https://aprendeit.com/?p=5074 Hello, cyber reader. Today, we’re diving into a world that might not be as tangible as the physical one, but it holds crucial importance in our day-to-day lives. We’re talking ...

La entrada Resource Management in Virtualized Environments: Techniques and Best Practices se publicó primero en Aprende IT.

]]>

Hello, cyber reader. Today, we’re diving into a world that might not be as tangible as the physical one, but it holds crucial importance in our day-to-day lives. We’re talking about resource management in virtualized environments. Have you ever wondered how all those data and processes that are generated and transferred every second on the network are managed?

Welcome to the World of Virtualization!

First off, it’s essential to understand what virtualization is. It’s a technology that allows us to create virtual versions of physical resources, like servers, storage systems, and networks. Sounds futuristic? Well, this is our present, and it is shaping up as the immediate future in IT management.

Virtual environments can provide great flexibility and efficiency, but they also present unique challenges when it comes to resource management. The key lies in knowing and applying techniques and best practices that allow us to maximize their potential.

It’s All About Balance

One of the keys in resource management in virtual environments is balance. This means that hardware and software resources must be balanced to ensure optimal performance. To do this, constant system monitoring is essential, something that can be done through various tools that will provide you with real-time data on resource usage.

Imbalance can lead to performance problems and system failures, something we obviously want to avoid. Make sure you’re always one step ahead, anticipating needs and planning resource allocation intelligently.

Automation: Your Best Ally

Did you know that it’s possible to automate much of the resource management in virtual environments? This is done through what is known as “automation policies,” which are rules that you can set up for the system to perform actions automatically based on certain criteria.

For example, you can set a policy that automatically increases storage capacity when a certain percentage of usage is reached. This way, you can prevent situations where it runs out of storage space, which could lead to service interruptions and data loss.

Automation can also be useful in maintaining system security, for example, by setting up policies that automatically install the latest security updates or perform data backups at regular intervals.

The Value of Foresight

If you’re able to foresee the needs of your system, you’ll be in a good position to manage resources efficiently in virtual environments. This involves constantly tracking resource usage trends and patterns, and using this information to make informed decisions.

For example, if you observe that resource demand regularly increases at certain times of the day, you can schedule more resources to be allocated during those periods. This will help you maintain high performance even during peak demand times.

Also, having foresight means you can anticipate and prepare for future events that might affect your system. For example, if a new application is about to launch that is likely to attract a large number of users, you can anticipate and allocate more resources to handle the increase in demand.

The Importance of Good Design

A good design of the virtual infrastructure is crucial for efficient resource management. This involves considering factors like redundancy, fault tolerance, load balancing, scalability, and security.

A well-thought-out design can help you maximize resource usage, avoid bottlenecks, and provide a high level of performance and availability. Additionally, a proper design will allow you to quickly adapt to changes and new needs that may arise.

Continuous Learning is Key

Resource management in virtual environments is a field that is constantly evolving. Technologies, techniques, and best practices change rapidly, so staying up-to-date is vital.

Make sure to invest in continuous learning, both for you and your team. Participate in webinars, workshops, courses, and other learning opportunities. Keep an eye on the latest trends and developments in the field of virtualization and resource management.

Also, remember that learning isn’t just about learning new things, but also about sharing knowledge. Foster a culture of learning within your team, where everyone feels comfortable sharing their ideas and experiences.

In addition, collaboration doesn’t have to be limited to your team or your organization. Participate in professional forums and networks, where you can connect with other experts in the field and learn from their experiences.

Managing resources in virtual environments can be a challenge, but with the right techniques and best practices, it can become a powerful tool for improving the efficiency and flexibility of your system. Remember, at the end of the day, effective resource management is not just about technology, but also about the people who use it. So, maintain a positive attitude, keep learning, and never stop improving.

We hope this article has provided some clarity and inspiration on your path to efficiency in managing resources in virtualized environments. And while there may not be a conclusion per se, I believe you’ve grasped the main idea: with the correct techniques and practices, the management of these environments becomes less daunting and more effective. Until next time!

La entrada Resource Management in Virtualized Environments: Techniques and Best Practices se publicó primero en Aprende IT.

]]>
https://aprendeit.com/en/resource-management-in-virtualized-environments-techniques-and-best-practices/feed/ 0
How to mount a disk in WSL and access it from the shell https://aprendeit.com/en/how-to-mount-a-disk-in-wsl-and-access-it-from-the-shell/ https://aprendeit.com/en/how-to-mount-a-disk-in-wsl-and-access-it-from-the-shell/#respond Mon, 01 May 2023 05:46:54 +0000 https://aprendeit.com/?p=4876 Windows Subsystem for Linux (WSL) is a feature of Windows that allows users to run a Linux environment on Windows. One of the advantages of WSL is that users can ...

La entrada How to mount a disk in WSL and access it from the shell se publicó primero en Aprende IT.

]]>
Windows Subsystem for Linux (WSL) is a feature of Windows that allows users to run a Linux environment on Windows. One of the advantages of WSL is that users can access files on their Windows hard drive from Linux, allowing them to work on Linux projects using files stored on their Windows hard drive.

In this article, we’ll show you how to mount a disk in WSL and access it from Linux. Keep reading to learn more.

What is WSL?

WSL is a feature of Windows that allows users to run a Linux distribution on Windows. WSL is a compatibility layer that translates Linux system calls into Windows system calls, allowing users to run Linux applications on Windows.

WSL is an extremely useful feature for developers who need to work on Linux projects while using Windows as their primary operating system. The ability to access Windows files from Linux in WSL is one of the advantages of this feature.

How to mount a disk in WSL

Mounting a disk in WSL is a simple process that can be done with a few commands on the command line.

Open the “Terminal” application in WSL. If you don’t have WSL installed, you can download it from the Microsoft Store.

Type the following command in the terminal to ensure you have the necessary permissions to mount the disk:

sudo mkdir /mnt/e

This command will create a folder called “e” in the /mnt location. The “sudo” prefix will give you administrator permissions to run the command.

Next, mount the E: disk to the /mnt/e folder with the following command:

sudo mount -t drvfs E: /mnt/e

This command uses the “mount” tool to mount the E: disk to the /mnt/e folder. The “-t drvfs” parameter indicates that the Windows file system driver is being used to mount the disk.

Now you should be able to access the E: disk from the WSL terminal in the /mnt/e folder. You can switch to the E: directory with the following command:

cd /mnt/e

How to access a mounted disk in WSL from the shell

Once you’ve mounted the disk in WSL, you can access it from the Linux terminal.

Open the Linux terminal in WSL.

To access the E: disk, switch to the /mnt/e directory with the following command:

cd /mnt/e

Now you should be able to see the files and folders on the E: disk from the Linux terminal in WSL. You can use the usual Linux commands to work with these files and folders.
How to unmount a disk in WSL

To unmount a disk in WSL, use the following command:

sudo umount /mnt/e

This command will unmount the E: disk from the /mnt/e folder in WSL.

La entrada How to mount a disk in WSL and access it from the shell se publicó primero en Aprende IT.

]]>
https://aprendeit.com/en/how-to-mount-a-disk-in-wsl-and-access-it-from-the-shell/feed/ 0
Introduction to Vagrant: Managing Virtualized Development Environments https://aprendeit.com/en/introduction-to-vagrant-managing-virtualized-development-environments/ https://aprendeit.com/en/introduction-to-vagrant-managing-virtualized-development-environments/#respond Thu, 27 Apr 2023 21:39:52 +0000 https://aprendeit.com/?p=4846 Hey everyone! Today we’re going to dive into the world of Vagrant, a fantastic tool that allows us to manage virtualized development environments quickly and easily. If you’re a developer, ...

La entrada Introduction to Vagrant: Managing Virtualized Development Environments se publicó primero en Aprende IT.

]]>
Hey everyone! Today we’re going to dive into the world of Vagrant, a fantastic tool that allows us to manage virtualized development environments quickly and easily. If you’re a developer, you know how difficult it can be to configure and maintain consistent and efficient development environments. Well, Vagrant is the solution to those problems. Let’s check it out!

What is Vagrant and why should you use it?

Vagrant is an open-source tool that allows us to create, configure, and manage virtualized development environments. With Vagrant, we can have a uniform and controlled development environment on our machine, regardless of the operating system we use. This way, we avoid compatibility issues and can focus on what really matters: developing!

But what are the advantages of Vagrant? Well, some of them are:

  • It facilitates collaboration among developers since everyone can work in the same environment.
  • It simplifies the configuration and management of virtual machines.
  • It allows for the automation of the creation and provisioning of development environments.
  • It encourages the use of good development practices, such as infrastructure as code.

Installing and configuring Vagrant

To install Vagrant, we first need to have a virtualization provider on our machine. One of the most popular ones is VirtualBox, but we can also use VMware, Hyper-V, among others. In this article, we will focus on VirtualBox. To install it, simply follow the instructions on the official VirtualBox website.
Once the virtualization provider is installed, we can download Vagrant from its official website. There we will find versions for Windows, macOS, and Linux. Download and install the appropriate version for your operating system.

Getting started with Vagrant

Now that we have Vagrant installed, let’s create our first virtualized development environment. To do so, we will follow these steps:

Open a terminal and create a new directory for our project:

mkdir my-first-vagrant-environment
cd my-first-vagrant-environment

Initialize Vagrant in the directory:

vagrant init

This command will create a file called Vagrantfile in our directory. This file is the key to configure and customize our virtualized development environment.

Edit the Vagrantfile with your favorite text editor and add the following line:

config.vm.box = "hashicorp/bionic64"

This line indicates that we will use the “hashicorp/bionic64” image as the base for our virtual machine. This image is a 64-bit version of Ubuntu 18.04 (Bionic Beaver). There are many other images available in the official Vagrant catalog, which you can explore in Vagrant Cloud.

Start the virtual machine with the command:

vagrant up

Vagrant will download the image (if it hasn’t already) and create a new virtual machine based on it. This process may take a while, depending on the speed of your internet connection and your computer.

Once the virtual machine is up and running, we can connect to it via SSH:

vagrant ssh

Congratulations! You are now connected to your first virtualized development environment with Vagrant. You can start installing software, developing applications, and experimenting without fear of breaking your local environment.

Provisioning environments

One of the most interesting features of Vagrant is provisioning, which allows us to automate the configuration and installation of software on our virtual machines. Vagrant is compatible with several provisioning systems, such as Shell, Puppet, Ansible, and Chef, among others.
To illustrate how provisioning works, we will use a simple Shell script. Add the following lines to your Vagrantfile, just below config.vm.box = “hashicorp/bionic64”:

config.vm.provision "shell", inline: <<-SHELL
    sudo apt-get update
    sudo apt-get install -y git nginx
SHELL

These lines indicate that Vagrant should run a Shell script that updates the Ubuntu package repositories and installs Git and Nginx. To apply these changes, we must reprovision our virtual machine with the command:

vagrant reload --provision

Once the process is complete, our virtual machine will have Git and Nginx installed.

Basic Vagrant commands

Here’s a list of some basic Vagrant commands that will be useful in your day-to-day:

  • vagrant init: Initializes a new Vagrant environment in the current directory.
  • vagrant up: Starts the virtual machine.
  • vagrant ssh: Connects to the virtual machine via SSH.
  • vagrant halt: Shuts down the virtual machine.
  • vagrant reload: Restarts the virtual machine.
  • vagrant destroy: Deletes the virtual machine and all its resources.
  • vagrant status: Shows the status of the virtual machine.
  • vagrant global-status: Shows the status of all virtual machines on your system.
  • vagrant box: Manages virtual machine images (boxes) on your system.

Working with multiple virtual machines

Vagrant allows us to easily manage multiple virtual machines in the same project. To do so, we simply need to add a new virtual machine definition in our Vagrantfile. For example, if we want to add a second virtual machine with CentOS 7, we could do the following:

config.vm.define "centos" do |centos|
    centos.vm.box = "centos/7"
    centos.vm.hostname = "centos.local"
    centos.vm.network "private_network", ip: "192.168.33.20"
end

With this configuration, we have created a new virtual machine called “centos” based on the “centos/7” image. Additionally, we have assigned it a hostname and an IP address on a private network.

To start both virtual machines, simply run the vagrant up command. If we want to start only one of them, we can specify its name:

vagrant up centos

We can connect to the CentOS virtual machine via SSH with the following command:

vagrant ssh centos

File synchronization between the host and the virtual machine

Vagrant facilitates file synchronization between our host machine and the virtual machines. By default, the directory where our Vagrantfile is located is automatically synchronized with the /vagrant directory inside the virtual machine. This allows us to easily share files between both environments.

If we want to configure a custom shared folder, we can do so by adding the following line to our Vagrantfile:

config.vm.synced_folder "my-local-folder", "/my-remote-folder"

This line indicates that the “my-local-folder” folder on our host machine will be synchronized with the “/my-remote-folder” folder in the virtual machine. Vagrant will take care of keeping both directories synchronized automatically.

Networking in Vagrant

Vagrant offers us several options to configure the network in our virtual machines. Some of the most common ones are:

Private network: Allows virtual machines to communicate with each other and with the host machine through a private network. To configure a private network, add the following line to your Vagrantfile:

config.vm.network "private_network", ip: "192.168.33.10"

Public network: Connects the virtual machine directly to the public network, allowing other machines on the network to access it. To configure a public network, add the following line to your Vagrantfile:

config.vm.network "public_network"

Port forwarding: Allows access to services in the virtual machine through a specific port on the host machine. To configure port forwarding, add the following line to your Vagrantfile:

config.vm.network "forwarded_port", guest: 80, host: 8080

This line indicates that port 80 in the virtual machine will be forwarded to port 8080 on our host machine.

And that’s it! With these basics, you should be able to start using Vagrant to manage your virtual development environments. Happy developing!

La entrada Introduction to Vagrant: Managing Virtualized Development Environments se publicó primero en Aprende IT.

]]>
https://aprendeit.com/en/introduction-to-vagrant-managing-virtualized-development-environments/feed/ 0
How to Monitor Your ESX CPU and RAM Resources from Python https://aprendeit.com/en/how-to-monitor-your-esx-cpu-and-ram-resources-from-python/ https://aprendeit.com/en/how-to-monitor-your-esx-cpu-and-ram-resources-from-python/#respond Mon, 17 Apr 2023 17:00:16 +0000 https://aprendeit.com/?p=4765 In this article, I’ll show you how to monitor your ESX CPU and RAM resources from Python. To do this, we’ll use a Python script that will allow us to ...

La entrada How to Monitor Your ESX CPU and RAM Resources from Python se publicó primero en Aprende IT.

]]>
In this article, I’ll show you how to monitor your ESX CPU and RAM resources from Python. To do this, we’ll use a Python script that will allow us to monitor the resources used on our ESX hypervisor.

Before we get started, it’s important to note that monitoring your ESX resources is crucial to ensuring that your infrastructure is running efficiently and avoiding performance and downtime issues. Additionally, by automating this process with a Python script, you can save time and effort by not having to do it manually.

Now, to begin the process of monitoring your ESX resources from Python, you’ll need to install the following libraries:

  • pyVmomi: a Python library that provides an API for interacting with vSphere and ESX.
  • ssl: a Python library that provides socket layer security functionality.

Once you have installed these libraries, you can start writing your script to monitor your ESX resources. The script we’ll be using in this article will connect to your ESX and retrieve the host hardware information, as well as the information for running virtual machines. It will then calculate the total amount of CPU and RAM assigned to the virtual machines and display the results in the output.

But don’t worry if all of this seems a bit complicated! I’ll explain how the script works step by step.

First, we import the necessary libraries and set the login credentials for our ESX hypervisor:

import ssl
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim

# ESX hypervisor login information
hostname = 'esx_hostname_or_ip'
username = 'username'
password = 'password'

Next, we create a custom SSL context that will allow us to connect to the ESX hypervisor:

# Create a custom SSL context
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE

# Connect to the ESX hypervisor with the custom SSL context
si = SmartConnect(host=hostname, user=username, pwd=password, sslContext=context)
content = si.RetrieveContent()

Then, we retrieve the host hardware information using the content object we created in the previous step:

# Get the host hardware information
host_system = content.rootFolder.childEntity[0].hostFolder.childEntity[0].host[0].summary.hardware
num_cpu_cores = host_system.numCpuCores
num_cpu_threads = host_system.numCpuThreads
total_memory = host_system.memorySize / (1024 ** 3)
cpu_model = host_system.cpuModel

After that, we retrieve the information for running virtual machines using the content object again:

# Get information for running virtual machines
vm_properties = ['name', 'config.hardware.numCPU', 'config.hardware.memoryMB']
vm_view = content.viewManager.CreateContainerView(content.rootFolder, [vim.VirtualMachine], True)
vms = vm_view.view
vm_view.Destroy()

Next, we calculate the total amount of CPU and RAM assigned to the running virtual machines and display it in the output:

# Display the total amount of CPU and RAM assigned to the virtual machines
print(f"Total amount of CPU assigned to the virtual machines: {num_vcpu_assigned}")
print(f"Total amount of memory assigned to the virtual machines: {total_memory_assigned:.2f} GB")
print(f"Total memory of the host: {total_memory:.2f} GB")

Finally, we close the connection to the ESX hypervisor:

# Disconnect from the ESX hypervisor
Disconnect(si)

With this script, we can obtain valuable information about our ESX resources and ensure that everything is running properly. Additionally, by using a Python script to monitor our ESX resources, we can automate this process and save time and effort.

In summary, monitoring your ESX CPU and RAM resources is essential to ensuring that your infrastructure is running efficiently and avoiding performance and downtime issues. By automating this process with a Python script, you can save time and effort by not having to do it manually. I hope this article has been helpful to you and I encourage you to try this script in your own environment!

La entrada How to Monitor Your ESX CPU and RAM Resources from Python se publicó primero en Aprende IT.

]]>
https://aprendeit.com/en/how-to-monitor-your-esx-cpu-and-ram-resources-from-python/feed/ 0
Network and FC commands for ESXi https://aprendeit.com/en/network-and-fc-commands-for-esxi/ https://aprendeit.com/en/network-and-fc-commands-for-esxi/#respond Fri, 13 Jan 2023 16:13:29 +0000 https://aprendeit.com/?p=3954 The VMware infrastructure virtualization system, known as vSphere, uses the Enhanced Scalability and Performance (ESX) operating system to provide a high-efficiency and performance virtualization environment. ESX includes a set of ...

La entrada Network and FC commands for ESXi se publicó primero en Aprende IT.

]]>
The VMware infrastructure virtualization system, known as vSphere, uses the Enhanced Scalability and Performance (ESX) operating system to provide a high-efficiency and performance virtualization environment. ESX includes a set of commands that can be used to manage and configure the network system and storage area network (SAN).

Network Commands

Let’s start with some basic ESX commands for managing the network system.

esxcli network ip interface ipv4 set -i vmnic0 -I 192.168.1.100 -N 255.255.255.0 -G 192.168.1.1
The above command allows you to configure IP addresses, subnet masks, and gateway addresses for the ESX system’s network interfaces.
esxcli network vswitch standard add -v vSwitch1
This command allows you to create and configure “vswitches” (virtual switches) in ESX. A vSwitch is a logical component that allows virtual machines to be connected to a physical network.
esxcli network vswitch standard uplink add -u vmnic0 -v vSwitch1
Once the vSwitch is created, we can add network interfaces to it using this command:
esxcli network firewall set --enabled true
This command allows you to configure and manage the ESX firewall:
esxcli network firewall ruleset list
This command allows you to view the firewall rule state:
esxcli network firewall ruleset rule add -r sshServer -p TCP -o inbound -y allow
To add a rule to the firewall, we can use this command.

SAN commands

Now let’s see some ESX commands for managing SAN.

This command allows you to manage device-to-host mapping and view the state of the mapped storage devices on a host:
esxcli storage nmp device list
This command allows you to manage SAN-connected storage on an ESX host and view the state of the SAN-connected storage devices on a host:
esxcli storage san fc list
The esxcli storage vmfs command allows you to manage Virtual Machine File System (VMFS) volumes in ESX, and this command allows you to view the state of the VMFS volumes on a host:
esxcli storage vmfs extent list

 

Other useful ESX commands for managing the network and storage area network (SAN) include:

This command allows you to configure the name and vSwitch of a port group:

esxcli network vswitch standard portgroup set -p "Management Network" -v vSwitch0

This command allows you to configure the security policy of a port group, allowing for promiscuous mode:

esxcli network vswitch standard portgroup policy security set -p "Management Network" -m promiscuous-mode -M accept

This command allows you to configure the VLAN policy of a port group:

esxcli network vswitch standard portgroup policy vlan set -p "Management Network" -v 4095

This command allows you to add a storage device routing rule for a Storage Array Type Plugin (SATP):

esxcli storage nmp satp rule add -s "VMW_SATP_ALUA" -V "VMW_VAAI_NFS" -M "VMW_NMP_ALUA_DSS"

This command allows you to view the list of storage adapters on an ESX host

esxcli storage core adapter list

This command allows you to view information about a specific storage device on an ESX host:

esxcli storage core device list -d naa.600601602ac0000000120000035000001

In summary, ESX offers a wide range of useful commands for managing and configuring the network system and SAN. These commands are essential for the management and maintenance of high-scale virtualization environments, providing precise and detailed control over the network and storage operation on an ESX host.

La entrada Network and FC commands for ESXi se publicó primero en Aprende IT.

]]>
https://aprendeit.com/en/network-and-fc-commands-for-esxi/feed/ 0
How to get started with docker https://aprendeit.com/en/how-to-get-started-with-docker/ https://aprendeit.com/en/how-to-get-started-with-docker/#respond Sat, 22 Jan 2022 19:14:38 +0000 https://aprendeit.com/?p=2641 Hi, I’ve been wanting to do this article on how to get started with docker for a while. We appreciate you sharing this article on your social networks and/or leaving ...

La entrada How to get started with docker se publicó primero en Aprende IT.

]]>
Hi, I’ve been wanting to do this article on how to get started with docker for a while.

We appreciate you sharing this article on your social networks and/or leaving a comment.

Let’s get started!

1- What is docker?

There are people who consider docker to be a virtualization system like KVM, Vmware, etc. This is false. Docker is a container system like LXC but more advanced. It has better management of the raised instances and has a template management system.

That is to say, Docker is a system to abstract the application and make its ecosystem independent of the operating system. Making everything configured inside a container to run correctly in any operating system with docker installed.

2- What advantages does it have?

The advantages are several depending on what we compare it with.

If we compare it with running applications on a system directly, the main advantage is compatibility, since what has been tested in the container, in the same container of another system will work the same.

If we refer to advantage over using a full virtualization, the main advantage is that each container uses practically the memory of the application while an instance of KVM, Vmware, etc. requires also memory consumption for the kernel of the virtual system, etc.

Another advantage is that you can run applications as if you had a different system. That is to say, in the host system we have a CentOS system for example and in the container we can have, Free BSD or Debian, or Arch or any other. So if in a system it works better than in the host we can use this advantage.

3- How can I use it?

Well it can be used to create development environments and then upload the container to production (keep in mind that before putting anything in production with docker you must secure the host and the container to avoid problems). This way we can avoid problems in code deployments.

The first thing to do is to install docker. In CentOS it is done in the following way:  #yum install docker -y

Instalacion docker CentOS

In debian and derivatives: #apt install docker.io

After installing it, if it is a modern system, based on systemd, we start the service: #systemctl start docker

If you do not have systemd, run: #service docker start

4- Useful commands

Start containers (even if the images have not been downloaded):

docker run -i -t -d   IMAGEN:VERSION

Where the image and version can be specified as follows:

docker run -i -t -d   centos:latest

We can define a name for the container with –name MY_NAME

[root@localhost ~]# docker run -i -t -d --name testing debian:9
Unable to find image 'debian:9' locally
Trying to pull repository docker.io/library/debian ... 
9: Pulling from docker.io/library/debian
54f7e8ac135a: Pull complete 
Digest: sha256:df6ebd5e9c87d0d7381360209f3a05c62981b5c2a3ec94228da4082ba07c4f05
Status: Downloaded newer image for docker.io/debian:9
b6f568b78470b417b8a141f4b7c5686420df7cc1050402239ab1847310a67116
[root@localhost ~]# 

You can specify a port that will be forwarded from the host machine to the container:

docker run -i -t -d -p PUERTO_EXTERIOR:INTERIOR IMAGEN

Or it can also be done by specifying the host ip:

docker run -i -t -d -p IP_ANFITRION:PUERTO_EXTERIOR:INTERIOR IMAGEN

Adding “–restart always” to the equation, it is achieved that whenever the container is stopped, it is restarted. Even on host restart:

docker run -i -t -d -p PUERTO_EXTERIOR:INTERIOR --restart always IMAGEN

To create a container and not to lift it immediately:

docker create -i -t centos:6 /bin/bash

Download images and manage them

To download an image and have it available at the time of raising a new container without having to wait for it to be downloaded from docker-hub, we only have to do the following:

docker pull IMAGEN:VERSION

Or also:

docker pull IMAGEN

For example:

#Eligiendo version
docker pull centos:7
#o seleccionando la ultima disponible
docker pull centos:latest

We can also see the images available locally by running:

docker images

For example:

ger@portatil$ sudo docker images
[sudo] contraseña para ger: 
REPOSITORY                                  TAG                 IMAGE ID            CREATED             SIZE
debian                                      9                   4879790bd60d        9 days ago          101MB
ubuntu                                      18.04               ea4c82dcd15a        5 weeks ago         85.8MB
centos                                      6                   0cbf37812bff        6 weeks ago         194MB
centos                                      7                   75835a67d134        6 weeks ago         200MB
ubuntu                                      17.04               fe1cc5b91830        11 months ago       95.6MB

We can search for available images in docker hub:

ger@portatil$ sudo docker search ubuntu
NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
ubuntu                                                 Ubuntu is a Debian-based Linux operating sys…   8793                [OK]                
dorowu/ubuntu-desktop-lxde-vnc                         Ubuntu with openssh-server and NoVNC            244                                     [OK]
rastasheep/ubuntu-sshd                                 Dockerized SSH service, built on top of offi…   184                                     [OK]
consol/ubuntu-xfce-vnc                                 Ubuntu container with "headless" VNC session…   136                                     [OK]
ansible/ubuntu14.04-ansible                            Ubuntu 14.04 LTS with ansible                   95                                      [OK]
ubuntu-upstart                                         Upstart is an event-based replacement for th…   92                  [OK]                
neurodebian                                            NeuroDebian provides neuroscience research s…   55                  [OK]                
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          47                                      [OK]
ubuntu-debootstrap                                     debootstrap --variant=minbase --components=m…   40                  [OK]                
nuagebec/ubuntu                                        Simple always updated Ubuntu docker images w…   23                                      [OK]
tutum/ubuntu                                           Simple Ubuntu docker images with SSH access     18                                      
i386/ubuntu                                            Ubuntu is a Debian-based Linux operating sys…   15                                      

 

We can import a custom image:docker import /path/to/exampleimage.tgz:

[root@localhost ~]# docker import /tmp/debian-personalizado.tgz
[root@localhost ~]#

View the status of containers and their data

To see the created containers and their current status we only have to execute:

docker ps -a

For example:

[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
b6f568b78470        debian:9            "bash"              About a minute ago   Up About a minute                       testing
[root@localhost ~]# 

To raise a machine we only have to execute docker start CONTAINER_ID the ID can be found by runningdocker ps -a :

[root@localhost ~]# docker start b6f568b78470
b6f568b78470
[root@localhost ~]#

 

Container management

To stop a docker container docker stop CONTAINER_ID:

[root@localhost ~]# docker stop b6f568b78470
b6f568b78470
[root@localhost ~]#

And to delete a container docker stop CONTAINER_ID:

[root@localhost ~]# docker rm b6f568b78470
b6f568b78470
[root@localhost ~]#

We can make a copy of a container by executing:docker export -o filesystem.tar CONTAINER_ID:

[root@localhost ~]# docker export -o filesystem.tar b6f568b78470
[root@localhost ~]#

 

We can access a container console: docker exec -it “id of running container” bash:

[root@localhost ~]# docker exec -it b6f568b78470 bash
[root@b6f568b78470 ~]#

 

 

If you are interested in learning Docker you can purchase our book here.

Docker para novatosDocker para novatos

 

And this has been all about how to get started with docker, in a next post, we will discuss how to manage docker with python.

Remember that if you liked this post we appreciate if you share in your social networks and/or comment on the publication.

See you soon!

La entrada How to get started with docker se publicó primero en Aprende IT.

]]>
https://aprendeit.com/en/how-to-get-started-with-docker/feed/ 0