How to Run Docker on Bare Metal Cloud? Comprehensive Tutorial
Running critical applications and systems using Docker requires stable and continuous resource provisioning. In addition, Docker needs flexible and easy-to-configure hardware. Unfortunately, not every machine is best suited to run Docker. Failing to meet Docker’s resource requirements leads to application crashes and process termination.
In this article, you will learn what bare metal is and why it is suitable for running Docker. In addition, you will learn how to run Docker on a bare metal cloud solution provisioned by Cherry Servers.
#Prerequisites
You need a Cherry Servers account and adequate knowledge of how to use Ubuntu basic commands. We will install Ubuntu 24.04 on the selected bare metal server.
#What is bare metal, and why should you run Docker on it?
Usually, Chief Technology Officers(CTOs) compare virtual machines with Bare metal when choosing the infrastructure for hosting containerized Docker applications. Virtual machines have many detrimental drawbacks, such as resource underutilization and limited direct access to hardware. Also, virtual machines lag because of the abstraction layer that separates the application and the hardware. All of these virtual machine limitations aren’t experienced when running Docker on a bare metal server.
Bare Metal is a cloud infrastructure service that lets you own and use a physical machine that is not preinstalled with an operating system or application. The user is in full control of the storage, hardware, and network. No resources are shared with other tenants. The user can also configure the server's physical aspects. The user has unlimited access to the server and its hardware.
Below are the benefits of running Docker on the bare metal cloud:
- Bare metals optimize high performance: Bare metals are optimized to handle large loads and traffic. They were designed for applications that need extensive cloud resources. They can handle complex data processing and large-scale simulations. This is because bare metal environments offer a higher level of customization since you have complete control over hardware configurations, operating systems, and software stacks. In addition, they do not have any overhead layers that add more processes.
- Easy management: It is very easy to set up bare metal using a provider like Cherry Servers. It takes a click of a button to install an operating system, followed by a few commands that connect the bare metal server to your local terminal. A transition from using your local server or virtual machine to bare metal is easy and simple in terms of the skills needed. Unlike virtual servers, bare metal doesn't have a hypervisor or virtual layer that has to be managed. You run and manage your bare metal the way you want.
- Full customization: Bare metals allow you to set up your server the way you want and choose the hardware you need. Since you aren’t sharing resources with other tenants, you can fully utilize all the server's resources without worrying about noisy neighbors or performance degradation due to resource contention. This dedicated resource allocation is particularly advantageous for applications that require high levels of performance consistency and reliability, such as real-time analytics, intensive data processing, or large-scale database operations.
Ready to supercharge your Docker infrastructure? Scale effortlessly and enjoy flexible storage with Cherry Servers bare metal or virtual servers. Eliminate infrastructure headaches with free 24/7 technical support, pay-as-you-go pricing, and global availability.
#How to set up a Cherry Servers bare metal server
Setting up a bare metal involves creating a server instance and connecting it to your local terminal through SSH keys. Use the following step-by-step guide to set up a bare metal cloud server.
1. Generating and copying SSH keys
To connect your machine’s terminal with the bare metal, you must create and add SSH keys to the Cherry Servers platform. An SSH key is a passwordless mechanism used to authenticate and secure communication between a client and the server.
Before generating a new SSH key, checking if one already exists is the best practice to avoid overwriting it. Use the following command to check if there is an existing SSH key in your local terminal.
ls -al ~/.ssh
If there is no existing SSH key, use the following command to generate an SSH key labeled "docker-server" you will use to connect to the bare metal server:
ssh-keygen -t ed25519 -C "docker-server"
Next, check if the SSH key has been generated successfully by listing the available SSH keys:
ls -al ~/.ssh
You will get the following output that shows all the SSH keys you have created. The SSH key you just created is the one that ends with the ed25519 key type.
To add the SSH key to the Cherry Servers, copy the public SSH key you just created. Use the following command to open and copy the SSH key:
cat ~/.ssh/id_ed25519.pub
2. Adding SSH keys
After copying the key, head over to the Cherry Servers portal and click on the profile button located on the top right corner. Choose the “User” tab on the profile sections, not the “Team” tab. Under the “User”, you will find the SSH keys button, click on it. Next, click on the “Add +” button to add a new SSH key.
Next, add the SSH key and its label. Press the “Add” button to apply the changes.
3. Choosing a bare metal server instance
After adding an SSH key, create a bare metal instance by clicking on the “New instance” button on the Cherry Servers portal home page.
Cherry Servers has many bare metal options from which you can choose. Under the “Dedicated Servers” tab, select the bare metal plan that suits your needs. In this tutorial, we will use the Intel Gold 5315Y server.
After choosing your plan, you can select your suitable operating system and its version. For this tutorial, we will select Ubuntu 24.04.
4. Configuring the bare metal
Next, scroll down and add the Hostname and SSH key. By default, the SSH key you created previously will be the chosen SSH key. Next, pay and deploy the bare metal instance.
5. Connecting to the bare metal server
Once your bare metal instance has been deployed, the specifications and configuration for your bare metal will be available on the instance dashboard. You need to copy the Primary IP address located in the “Network” section at the bottom right corner as shown below.
Finally, use the following command on your local terminal to connect to the bare metal and start using it.
ssh root@[add-primary address here] -i ~/.ssh/id_rsa
Upon successful login, you will see the following output indicating that you are logged in as a root user with the hostname “Docker-Server” you just created.
6. Updating Ubuntu
After setting up the bare metal, run the following command to update Ubuntu libraries and packages.
sudo apt update && sudo apt upgrade
#Installing and running Docker on Bare Metal
Use the following steps to install Docker on a bare metal server.
1. Install dependency packages
Start by installing packages that enable the Ubuntu package manager to securely install Docker from its official repositories.
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
Next, add the GPG key to your bare metal server. The GPG (GNU Privacy Guard) key is used to verify the integrity and authenticity of the packages downloaded from Docker's repository. By adding the key to your server's keyring, you ensure that the packages are trusted and have not been tampered with.
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
2. Add the Docker repository to Ubuntu APT
Use the following command to add Docker's official repository to your Application Package Tool(APT) that allows you to install Docker packages directly from Docker, ensuring you get the latest stable versions and updates.
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
3. Update the server package index
After adding the GPG key and Docker repository to the APT, use the following command to synchronize the changes.
sudo apt update
4. Install Docker
Use the following command to install Docker. Here we are installing Docker Community Edition ( Docker CE ) which is free to download and use.
sudo apt-get install docker-ce -y
The command installs Docker alongside its plugins including docker-buildx-plugin, docker-ce-cli and docker-compose-plugin.
Docker autostarts upon installation. You can confirm this by running the command:
sudo systemctl status docker
Next, use the following command to ensure that the Docker daemon starts running when the bare metal boots every time.
sudo systemctl enable docker
5. Verify Docker installation success
Use the following command to check if Docker has been installed successfully.
sudo docker version
6. Add a user to the Docker group
Docker is configured to be executed by the root or sudo user ( regular user with root-level privileges ). The current setup will require you to invoke the sudo
command whenever running Docker commands, otherwise, you will get a 'permissions error' message every time you run Docker commands.
To seamlessly run Docker commands, add the currently logged-in user to the docker
group. This allows you to comfortably execute Docker commands as a regular user without sudo permissions. To do this, run the command:
sudo usermod -aG docker $USER
Next, run the following command:
newgrp docker
Finally, close the current shell and open a new one to start running docker commands without invoking sudo
. Alternatively, you can spawn a new shell session as shown.
su - $USER
Henceforth, you can run docker without invoking the sudo
command.
#Running Docker
This section covers how to run basic Docker commands. You will learn how to pull images and run containers from images.
1. Pulling an image
Use the following command to pull your first container image on the bare metal cloud:
docker pull [image_name]:[tag]
Below is an example of a docker pull
command that pulls the latest nginx image.
docker pull nginx:latest
When pulling an image, you will get the following output that shows the image components being downloaded.
Run the following command to list all available images. This will help you select which images to keep or remove.
docker images
You will get the following output that shows all the images you have pulled.
2. Creating a container
After pulling the image, use the following command to build a container using the Nginx image you pulled previously.
docker run -d -p 80:80 nginx:latest
The -d
flag runs the container in detached mode (in the background). Whereas, the -p 80:80
flag maps port 80 of your local machine to port 80 of the container, allowing you to access Nginx through http://localhost
.
Next, use the following command to list running containers and check their statuses.
docker ps
You will get the following output that shows the nginx container running.
3. Stopping containers
Use the following command to stop misbehaving or redundant images.
docker stop [container_id or container_name]
For example, you can stop the nginx container using its container ID.
docker stop 6253948d4f2d
4. Reading logs
Use the following command to get a comprehensive list of container errors and events through logs.
docker logs [container_id or container_name]
For example, you can get the nginx container logs using its container ID.
docker logs 6253948d4f2d
You will get the following logs.
#Managing Docker on Bare Metal
Below are different techniques to effectively manage your Docker resources using Cherry Servers’ bare metal platform.
#Controlling access to the bare metal hosting Docker
Cherry Servers offers built-in Role Based Access(RBAC) features that allow teams to delegate permissions and streamline collaboration. Access control helps maintain security while enabling efficient teamwork. Anyone with access to the infrastructure running the Docker engine can manipulate and edit containerized applications. The RBAC mechanism is important for authorizing and delegating access rights between developers. Not every developer needs to have full access to the bare metal.
This feature allows you to create a team and add members with different access roles. Below are different roles offered by the Cherry Servers portal:
- Owner role: Whoever creates a team is declared the team owner by default and possesses all access rights within the specified team.
- Admin role: The admin role is responsible for adding members who can access the bare metal and the Cherry Servers portal.
- Collaborator role: This role has minimal rights and access compared to other roles. This role only allows you to order services, view project details, and access the bare metal server.
Creating a team on the Cherry Servers portal allows you to organize your projects according to departments and add the right people to specific projects.
After creating a team you will be able to send invitations to members and assign them their roles and projects.
#Backing up Docker components
One of the greatest advantages of using Cherry Server’s bare metal solution is that you can easily back up the bare metal server contents and Docker’s components, such as images and volumes.
Use the following command to pause the container you want to back up. This command will create an image copy (a snapshot) of the paused container and save it in a repository.
sudo docker commit -p [container ID] [repository]
Next, use the following command to save a copy of the image to your prescribed file in the previously created repository. The path ~/my-backup.tar
indicates that the tar file my-backup.tar will be saved in the current user's home directory.
sudo docker save -o ~/my-backup.tar my-backup
The Cherry Servers has a backup storage feature that is located on the bare metal server overview page.
Ordering and activating backup storage will ensure that the image copy you saved in your current directory will be backed up in case you lose all your Docker resources. Once you activate the backup storage, your contents will be backed up. You can still extend the storage if your selected storage runs out.
#Conclusion
This article has shown how easy it is to set up a bare metal server on Cherry Servers. You have learned how to run Docker on a bare metal server, similar to running Docker on any host machine.
When running containerized applications, the focus has to be fully invested in building and optimizing applications, not troubleshooting resource issues. The world of software development is full of endless errors and unexpected bugs. Issues related to cloud infrastructure and resources can be prevented easily when the right bare metal server platform is chosen.
Cloud VPS - Cheaper Each Month
Start with $9.99 and pay $0.5 less until your price reaches $6 / month.