{"id":724,"date":"2025-02-07T09:19:27","date_gmt":"2025-02-07T09:19:27","guid":{"rendered":"https:\/\/forumweb.hosting\/blog\/?p=724"},"modified":"2025-02-07T09:21:39","modified_gmt":"2025-02-07T09:21:39","slug":"a-complete-guide-to-setting-up-docker-and-deploying-containers-on-vps","status":"publish","type":"post","link":"https:\/\/forumweb.hosting\/blog\/a-complete-guide-to-setting-up-docker-and-deploying-containers-on-vps\/","title":{"rendered":"A Complete Guide to Setting Up Docker and Deploying Containers on VPS"},"content":{"rendered":"<h3>Introduction<\/h3>\n<p>Docker has revolutionized the way developers deploy and manage applications. By allowing applications to run in isolated containers, Docker simplifies development workflows, ensures consistency across environments, and makes it easy to scale applications. In this guide, you&#8217;ll learn how to install Docker on a VPS, deploy your first container, and manage containerized applications effectively.<\/p>\n<p>Whether you&#8217;re hosting web applications, APIs, or microservices, Docker provides the flexibility and performance needed for modern infrastructure. Let&#8217;s dive into the complete setup process.<\/p>\n<h3>Prerequisites<\/h3>\n<p>Before starting, ensure you have the following:<\/p>\n<ul>\n<li>An Ubuntu 22.04 VPS<\/li>\n<li>Root or sudo privileges<\/li>\n<li>Basic knowledge of Linux commands<\/li>\n<\/ul>\n<h3>Step 1: Update Your System<\/h3>\n<p>It&#8217;s important to start with an updated system to avoid compatibility issues. Run the following commands to update all packages:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>sudo apt update &amp;&amp; sudo apt upgrade -y<\/p><\/blockquote>\n<p>This command ensures all existing packages are current, reducing potential conflicts during Docker installation.<\/p>\n<h3>Step 2: Install Required Dependencies<\/h3>\n<p>Docker requires some dependencies for secure communication and repository management. Install them with:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>sudo apt install apt-transport-https ca-certificates curl software-properties-common -y<\/p><\/blockquote>\n<p>These packages help in adding external repositories and handling HTTPS connections securely.<\/p>\n<h3>Step 3: Add Docker\u2019s Official GPG Key and Repository<\/h3>\n<p>Next, add Docker\u2019s GPG key to verify the authenticity of packages:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo gpg &#8211;dearmor -o \/usr\/share\/keyrings\/docker-archive-keyring.gpg<\/p><\/blockquote>\n<p>Then, add the Docker repository to your APT sources:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>echo \\&#8221;deb [arch=$(dpkg &#8211;print-architecture) signed-by=\/usr\/share\/keyrings\/docker-archive-keyring.gpg] https:\/\/download.docker.com\/linux\/ubuntu $(lsb_release -cs) stable\\&#8221; | sudo tee \/etc\/apt\/sources.list.d\/docker.list &gt; \/dev\/null<\/p><\/blockquote>\n<h3>Step 4: Install Docker Engine<\/h3>\n<p>Update the package database with the Docker packages from the newly added repo:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>sudo apt update<\/p><\/blockquote>\n<p>Now, install Docker:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>sudo apt install docker-ce -y<\/p><\/blockquote>\n<p>Verify the installation:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>docker &#8211;version<\/p><\/blockquote>\n<p>You should see the installed Docker version.<\/p>\n<h3>Step 5: Manage Docker as a Non-Root User<\/h3>\n<p>By default, Docker requires root privileges. To run Docker commands without <code>sudo<\/code>, add your user to the Docker group:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>sudo usermod -aG docker ${USER}<\/p><\/blockquote>\n<p>Apply the new group membership:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>newgrp docker<\/p><\/blockquote>\n<p>Now you can run Docker commands as a regular user.<\/p>\n<h3>Step 6: Deploy Your First Docker Container<\/h3>\n<p>To verify Docker\u2019s functionality, run the <code>hello-world<\/code> container:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>docker run hello-world<\/p><\/blockquote>\n<p>This command pulls a test image from Docker Hub and runs it in a container. If everything is set up correctly, you&#8217;ll receive a confirmation message.<\/p>\n<h3>Step 7: Running a Web Application with Docker<\/h3>\n<p>Let\u2019s deploy a simple NGINX web server to demonstrate Docker&#8217;s real-world use. Pull and run the NGINX image:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>docker run -d -p 80:80 nginx<\/p><\/blockquote>\n<p>Here\u2019s what this command does:<\/p>\n<ul>\n<li><code>-d<\/code>: Runs the container in detached mode (in the background).<\/li>\n<li><code>-p 80:80<\/code>: Maps port 80 of the host to port 80 of the container.<\/li>\n<li><code>nginx<\/code>: Specifies the image to run.<\/li>\n<\/ul>\n<p>Visit your server\u2019s IP address in a browser, and you should see the NGINX welcome page.<\/p>\n<h3>Step 8: Managing Docker Containers<\/h3>\n<p>To list running containers:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>docker ps<\/p><\/blockquote>\n<p>To view all containers (including stopped ones):<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>docker ps -a<\/p><\/blockquote>\n<p>To stop a running container:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>docker stop &lt;container_id&gt;<\/p><\/blockquote>\n<p>To remove a container:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>docker rm &lt;container_id&gt;<\/p><\/blockquote>\n<h3>Step 9: Working with Docker Images<\/h3>\n<p>To list downloaded images:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>docker images<\/p><\/blockquote>\n<p>To remove an image:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>docker rmi &lt;image_id&gt;<\/p><\/blockquote>\n<h3>Step 10: Using Docker Compose (Optional)<\/h3>\n<p>Docker Compose allows you to manage multi-container applications. Install it with:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>sudo apt install docker-compose -y<\/p><\/blockquote>\n<p>Example <code>docker-compose.yml<\/code> for running NGINX:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>version: &#8216;3&#8217;<br \/>\n\\nservices:<br \/>\n\\n web:<br \/>\n\\n image: nginx<br \/>\n\\n ports:<br \/>\n\\n &#8211; \\&#8221;80:80\\&#8221;<\/p><\/blockquote>\n<p>Run the composition:<\/p>\n<blockquote class=\"td_quote_box td_box_left\"><p>docker-compose up -d<\/p><\/blockquote>\n<h3>Conclusion<\/h3>\n<p>Congratulations! You&#8217;ve successfully set up Docker on your VPS and deployed containers. Docker streamlines application deployment, ensures consistency across environments, and simplifies scaling. As you explore Docker further, consider using orchestration tools like Kubernetes for managing complex containerized applications.<\/p>\n<p>Stay updated with Docker\u2019s official documentation for more advanced features, and keep experimenting to unlock the full potential of containerization!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Docker has revolutionized the way developers deploy and manage applications. By allowing applications to run in isolated containers, Docker simplifies development workflows, ensures consistency across environments, and makes it easy to scale applications. In this guide, you&#8217;ll learn how to install Docker on a VPS, deploy your first container, and manage containerized applications effectively. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":726,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"tags":[123,128,127,126,124,125],"_links":{"self":[{"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/posts\/724"}],"collection":[{"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/comments?post=724"}],"version-history":[{"count":1,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/posts\/724\/revisions"}],"predecessor-version":[{"id":725,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/posts\/724\/revisions\/725"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/media\/726"}],"wp:attachment":[{"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/media?parent=724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/categories?post=724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/forumweb.hosting\/blog\/wp-json\/wp\/v2\/tags?post=724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}