Docker is a containerization platform that allows the creation of consistent, isolated environments working seamlessly across various computing environments, from development to production.
At Hostinger, we have an Ubuntu 22.04 VPS template with both
docker-compose pre-installed, making it easy for you to start deploying and managing your applications using Docker containers.
To start using Docker, install the Docker template and follow these steps:
Step 1 - Connect to Your VPS
Open Terminal (Linux/macOS) or Command Prompt/PowerShell (Windows) on your local computer and enter the following command:
Replace vps_ip with your VPS IP address. You might be prompted to enter your VPS password.
Step 2 - Check the Docker Installation
To verify that Docker is installed, enter the following command:
You will get the Docker version information if it's installed correctly. Now check Docker Compose with the following command:
If installed correctly, this will display the version of Docker Compose.
Step 3 - Deploy Your First Docker Container
Pull a sample Docker image to test your setup. For instance, you can use the "Hello World" image:
docker run hello-world
This command will download and run the "Hello World" container.
Step 4 - Start Using Docker Compose
Create a new directory for your Docker Compose project and navigate to it:
Once inside your project directory, create a docker-compose.yml file using a text editor and define your services, networks, and volumes. Now you can start your services using the following command:
docker-compose up -d
This will start the services defined in your Docker Compose configuration by reading the configuration from the docker-compose.yml file in the current directory. The -d flag stands for detached so that the command runs in the background and returns to the command line instead of showing the logs of the running services.
Managing Docker Compose Services
To stop your Docker Compose services, use the following command:
To list all running containers, use:
That's it! Now you know how to use Docker in your Hostinger VPS.