{"id":16076,"date":"2026-09-22T14:01:56","date_gmt":"2026-09-22T13:01:56","guid":{"rendered":"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/"},"modified":"2026-09-22T14:01:56","modified_gmt":"2026-09-22T13:01:56","slug":"how-to-deploy-a-docker-container-on-a-vps","status":"publish","type":"post","link":"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/","title":{"rendered":"How to Deploy a Docker Container on a VPS"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_87 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#How_to_Deploy_a_Docker_Container_on_a_VPS_A_Complete_Guide\" >How to Deploy a Docker Container on a VPS: A Complete Guide<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#What_Is_Docker_and_Why_Use_It_on_a_VPS\" >What Is Docker and Why Use It on a VPS?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Prerequisites_Before_You_Begin\" >Prerequisites Before You Begin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Step_1_Connect_to_Your_VPS_via_SSH\" >Step 1: Connect to Your VPS via SSH<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Step_2_Install_Docker_on_Your_VPS\" >Step 2: Install Docker on Your VPS<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Install_Required_Dependencies\" >Install Required Dependencies<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Add_the_Docker_GPG_Key_and_Repository\" >Add the Docker GPG Key and Repository<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Install_Docker_Engine\" >Install Docker Engine<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Step_3_Pull_Your_Docker_Image\" >Step 3: Pull Your Docker Image<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Step_4_Run_Your_Docker_Container\" >Step 4: Run Your Docker Container<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Step_5_Manage_Container_Persistence_and_Restarts\" >Step 5: Manage Container Persistence and Restarts<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Using_Volumes_for_Persistent_Data\" >Using Volumes for Persistent Data<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Step_6_Use_Docker_Compose_for_Multi-Container_Applications\" >Step 6: Use Docker Compose for Multi-Container Applications<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Step_7_Secure_Your_Deployment\" >Step 7: Secure Your Deployment<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Configure_a_Firewall\" >Configure a Firewall<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Set_Up_SSL_with_a_Reverse_Proxy\" >Set Up SSL with a Reverse Proxy<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Keep_Images_Updated\" >Keep Images Updated<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/da-manager.com\/blog\/how-to-deploy-a-docker-container-on-a-vps\/#Final_Thoughts\" >Final Thoughts<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<p><html><br \/>\n<head><br \/>\n<title>How to Deploy a Docker Container on a VPS<\/title><br \/>\n<\/head><br \/>\n<body><\/p>\n<h1><span class=\"ez-toc-section\" id=\"How_to_Deploy_a_Docker_Container_on_a_VPS_A_Complete_Guide\"><\/span>How to Deploy a Docker Container on a VPS: A Complete Guide<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>Docker VPS deployment has become one of the most popular methods for hosting modern web applications, APIs, and microservices. By combining the flexibility of a Virtual Private Server with the consistency and portability of Docker containers, developers and system administrators can build reliable, scalable infrastructure without the complexity of managing bare-metal servers. Whether you are running a personal project or a production-grade application, this guide will walk you through everything you need to know to get started.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_Is_Docker_and_Why_Use_It_on_a_VPS\"><\/span>What Is Docker and Why Use It on a VPS?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker is an open-source platform that allows you to package applications and their dependencies into lightweight, portable containers. Unlike traditional virtual machines, Docker containers share the host operating system&#8217;s kernel, making them significantly faster to start and far less resource-intensive.<\/p>\n<p>A Virtual Private Server gives you dedicated resources within a shared physical server, providing root access, full control over your environment, and the ability to install any software you need. When you combine a VPS with Docker, you get a powerful deployment environment that is consistent across development, staging, and production. Your application behaves the same way regardless of where it is running, which eliminates the notorious &#8220;it works on my machine&#8221; problem.<\/p>\n<p>For developers looking to streamline their deployment workflows, Docker VPS deployment offers several key advantages:<\/p>\n<ul>\n<li>Rapid deployment and rollback capabilities<\/li>\n<li>Isolation between applications running on the same server<\/li>\n<li>Simplified dependency management<\/li>\n<li>Easy horizontal scaling<\/li>\n<li>Consistent environments across all stages of development<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Prerequisites_Before_You_Begin\"><\/span>Prerequisites Before You Begin<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before diving into the deployment process, make sure you have the following in place:<\/p>\n<ul>\n<li>A VPS running Ubuntu 22.04 or a similar Debian-based Linux distribution<\/li>\n<li>Root or sudo access to the server<\/li>\n<li>A basic understanding of the Linux command line<\/li>\n<li>SSH access configured on your local machine<\/li>\n<li>A Docker image ready to deploy, either from Docker Hub or a private registry<\/li>\n<\/ul>\n<p>If you are new to managing VPS environments, you may find it helpful to explore resources on <a href=\"https:\/\/da-manager.com\/blog\" target=\"_blank\">DA-Manager&#8217;s blog<\/a>, which covers a range of server administration topics for beginners and experienced users alike.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_1_Connect_to_Your_VPS_via_SSH\"><\/span>Step 1: Connect to Your VPS via SSH<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The first step in any Docker VPS deployment is to connect to your server. Open your terminal and use the following command, replacing the placeholder values with your actual server details:<\/p>\n<p><code>ssh username@your-server-ip-address<\/code><\/p>\n<p>Once connected, it is good practice to update your system packages before installing any new software:<\/p>\n<p><code>sudo apt update && sudo apt upgrade -y<\/code><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_2_Install_Docker_on_Your_VPS\"><\/span>Step 2: Install Docker on Your VPS<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Ubuntu&#8217;s default package repositories may not always contain the latest version of Docker. It is recommended to install Docker directly from the official Docker repository to ensure you have the most up-to-date release.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Install_Required_Dependencies\"><\/span>Install Required Dependencies<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Start by installing the packages needed to allow apt to use a repository over HTTPS:<\/p>\n<p><code>sudo apt install apt-transport-https ca-certificates curl software-properties-common -y<\/code><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Add_the_Docker_GPG_Key_and_Repository\"><\/span>Add the Docker GPG Key and Repository<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Next, add Docker&#8217;s official GPG key and set up the stable repository:<\/p>\n<p><code>curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo gpg --dearmor -o \/usr\/share\/keyrings\/docker-archive-keyring.gpg<\/code><\/p>\n<p><code>echo \"deb [arch=$(dpkg --print-architecture) signed-by=\/usr\/share\/keyrings\/docker-archive-keyring.gpg] https:\/\/download.docker.com\/linux\/ubuntu $(lsb_release -cs) stable\" | sudo tee \/etc\/apt\/sources.list.d\/docker.list > \/dev\/null<\/code><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Install_Docker_Engine\"><\/span>Install Docker Engine<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Update your package list and install Docker:<\/p>\n<p><code>sudo apt update && sudo apt install docker-ce docker-ce-cli containerd.io -y<\/code><\/p>\n<p>Verify the installation was successful by checking the Docker version:<\/p>\n<p><code>docker --version<\/code><\/p>\n<p>To avoid having to use <code>sudo<\/code> with every Docker command, add your user to the Docker group:<\/p>\n<p><code>sudo usermod -aG docker $USER<\/code><\/p>\n<p>Log out and back in again for this change to take effect.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_3_Pull_Your_Docker_Image\"><\/span>Step 3: Pull Your Docker Image<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>With Docker installed, you can now pull the image you wish to deploy. If you are using a public image from Docker Hub, the command is straightforward:<\/p>\n<p><code>docker pull nginx:latest<\/code><\/p>\n<p>If you are working with a private registry, you will need to log in first:<\/p>\n<p><code>docker login registry.yourdomain.com<\/code><\/p>\n<p>Then pull your image as usual using the full registry path.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_4_Run_Your_Docker_Container\"><\/span>Step 4: Run Your Docker Container<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Once your image has been pulled, you can run it as a container. The following example runs an Nginx web server and maps port 80 on the host to port 80 inside the container:<\/p>\n<p><code>docker run -d --name my-nginx -p 80:80 nginx:latest<\/code><\/p>\n<p>Here is a breakdown of the flags used:<\/p>\n<ul>\n<li><strong>-d<\/strong> \u2014 Runs the container in detached mode (in the background)<\/li>\n<li><strong>&#8211;name<\/strong> \u2014 Assigns a human-readable name to the container<\/li>\n<li><strong>-p<\/strong> \u2014 Maps a host port to a container port<\/li>\n<\/ul>\n<p>To confirm your container is running, use:<\/p>\n<p><code>docker ps<\/code><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_5_Manage_Container_Persistence_and_Restarts\"><\/span>Step 5: Manage Container Persistence and Restarts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>One of the most important considerations for Docker VPS deployment in a production environment is ensuring your container restarts automatically if the server reboots or the container crashes. You can achieve this by adding a restart policy when running the container:<\/p>\n<p><code>docker run -d --name my-nginx --restart unless-stopped -p 80:80 nginx:latest<\/code><\/p>\n<p>The <code>unless-stopped<\/code> policy ensures the container restarts automatically unless you explicitly stop it yourself.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Using_Volumes_for_Persistent_Data\"><\/span>Using Volumes for Persistent Data<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If your application writes data to the filesystem, you should use Docker volumes to persist that data beyond the container&#8217;s lifecycle:<\/p>\n<p><code>docker run -d --name my-app --restart unless-stopped -v \/home\/user\/app-data:\/app\/data -p 8080:8080 my-app-image<\/code><\/p>\n<p>This maps a directory on your VPS to a directory inside the container, ensuring data is not lost when the container is stopped or replaced.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_6_Use_Docker_Compose_for_Multi-Container_Applications\"><\/span>Step 6: Use Docker Compose for Multi-Container Applications<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For more complex applications that require multiple services \u2014 such as a web application alongside a database and a caching layer \u2014 Docker Compose is the recommended tool. It allows you to define all your services in a single <code>docker-compose.yml<\/code> file and manage them together.<\/p>\n<p>Install Docker Compose on your VPS:<\/p>\n<p><code>sudo apt install docker-compose-plugin -y<\/code><\/p>\n<p>A basic <code>docker-compose.yml<\/code> file might look like this:<\/p>\n<p><code>version: '3.8'<br \/>\nservices:<br \/>\n&nbsp;&nbsp;web:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;image: nginx:latest<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;ports:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- \"80:80\"<br \/>\n&nbsp;&nbsp;database:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;image: postgres:15<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;environment:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;POSTGRES_PASSWORD: securepassword<\/code><\/p>\n<p>To start all services defined in the file, navigate to the directory containing the file and run:<\/p>\n<p><code>docker compose up -d<\/code><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_7_Secure_Your_Deployment\"><\/span>Step 7: Secure Your Deployment<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Security is a critical aspect of any Docker VPS deployment. Here are some essential steps to harden your setup:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Configure_a_Firewall\"><\/span>Configure a Firewall<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Use UFW (Uncomplicated Firewall) to restrict access to only the ports your application needs:<\/p>\n<p><code>sudo ufw allow OpenSSH<br \/>\nsudo ufw allow 80\/tcp<br \/>\nsudo ufw allow 443\/tcp<br \/>\nsudo ufw enable<\/code><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Set_Up_SSL_with_a_Reverse_Proxy\"><\/span>Set Up SSL with a Reverse Proxy<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Never expose your application directly without SSL. Use Nginx or Caddy as a reverse proxy in front of your containers, and obtain a free SSL certificate via Let&#8217;s Encrypt. Caddy, in particular, handles SSL certificate issuance and renewal automatically, making it an excellent choice for Docker-based deployments.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Keep_Images_Updated\"><\/span>Keep Images Updated<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Regularly pull updated versions of your base images to ensure you have the latest security patches applied. Consider automating this process using tools such as Watchtower.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Final_Thoughts\"><\/span>Final Thoughts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Deploy a Docker Container on a VPS<\/p>\n<p>How to Deploy a Docker Container on a VPS: A Complete Guide<\/p>\n<p>Docker VPS deployment has become one of the most popular methods for hosting modern web applications, APIs, and microservices. By combining the flexibility of a Virtual Private Server with the<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mbp_gutenberg_autopost":false,"footnotes":""},"categories":[147],"tags":[],"class_list":["post-16076","post","type-post","status-publish","format-standard","category-general"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts\/16076","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/comments?post=16076"}],"version-history":[{"count":0,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/posts\/16076\/revisions"}],"wp:attachment":[{"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/media?parent=16076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/categories?post=16076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/da-manager.com\/blog\/wp-json\/wp\/v2\/tags?post=16076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}