{"id":3354,"date":"2024-05-19T16:40:47","date_gmt":"2024-05-19T08:40:47","guid":{"rendered":"https:\/\/blog.zengqq.com.cn\/?p=3354"},"modified":"2024-05-19T16:40:47","modified_gmt":"2024-05-19T08:40:47","slug":"installing-docker-and-docker-compose-on-a-raspberry-pi","status":"publish","type":"post","link":"https:\/\/blog.zengqq.com.cn\/?p=3354","title":{"rendered":"Installing Docker and Docker Compose on a Raspberry Pi"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\u8981\u77e5\u9053\u6811\u8393\u6d3e\u5b89\u88c5Docker-compose\u6709\u70b9\u4e0d\u4e00\u6837<\/h1>\n\n\n\n<p>Running containers on a Raspberry Pi is a great way to run lightweight, isolated applications without the overhead of installing them directly on Raspbian. Here, we&#8217;ll guide you through the steps to install Docker and Docker Compose on your Raspberry Pi, ensuring that you can take full advantage of containerized applications.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A Raspberry Pi with Raspbian OS installed.<\/li>\n\n\n\n<li>An internet connection.<\/li>\n\n\n\n<li>Terminal access to your Raspberry Pi.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Step-by-step Installation Guide<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Update and Upgrade Raspbian OS<\/h3>\n\n\n\n<p>Before installing any new software, it&#8217;s always a good practice to update and upgrade your existing packages:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt update\nsudo apt upgrade -y\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Install Docker on Raspberry Pi<\/h3>\n\n\n\n<p>Docker provides an installation script that simplifies the process of getting Docker on Raspberry Pi.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Download and run Docker installation script\ncurl -fsSL https:\/\/get.docker.com -o get-docker.sh\nsudo sh get-docker.sh\n\n# Add 'pi' user to the 'docker' group\nsudo usermod -aG docker pi\n<\/pre>\n\n\n\n<p>You can verify that Docker was installed correctly:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Install Docker Compose<\/h3>\n\n\n\n<p>Docker Compose doesn\u2019t come installed with Docker. Installing Docker Compose on a Raspberry Pi requires a slightly different approach compared to a standard Linux machine because of the Pi&#8217;s ARM architecture.<\/p>\n\n\n\n<p>First, we&#8217;ll install required dependencies:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install -y libffi-dev libssl-dev python3 python3-pip\n<\/pre>\n\n\n\n<p>Now, install Docker Compose using pip:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo pip3 install docker-compose\n<\/pre>\n\n\n\n<p>To confirm the successful installation of Docker Compose:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">docker-compose --version\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Test Your Installation<\/h3>\n\n\n\n<p>To make sure that both Docker and Docker Compose are working as expected, let&#8217;s run a test container:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># Pull and run a basic 'hello-world' Docker image\ndocker run hello-world\n<\/pre>\n\n\n\n<p>The output should indicate that Docker is working correctly.&nbsp;<\/p>\n\n\n\n<p>For Docker Compose, create a simple `docker-compose.yml file:<\/p>\n\n\n\n<p>Paste the following content:<\/p>\n\n\n\n<p><code>docker-compose.yml<\/code><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">version: '3'\nservices:\n  hello-world:\n    image: hello-world\n<\/pre>\n\n\n\n<p>Now, run the composition:<\/p>\n\n\n\n<p>You should see Docker Compose starting the hello-world service and the same hello message from Docker.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Clean Up (Optional)<\/h3>\n\n\n\n<p>If you wish to clean up after the test, you can remove the downloaded images:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion and Alternatives<\/h2>\n\n\n\n<p>By following these steps, you&#8217;ve successfully installed Docker and Docker Compose on your Raspberry Pi. Now, you&#8217;re all set to explore the world of containerized applications with Docker on Raspbian. With the rising popularity of using Docker on Raspberry Pi, the opportunities for development and deployment are vast. Whether for home automation, IoT projects, or lightweight web servers, you&#8217;ve unlocked a versatile tool in your Raspberry Pi toolkit. If you want to use containers on a whole fleet of devices you might need further container automation. Here we can help you with automated installations but also very granular and simple&nbsp;<a href=\"https:\/\/qbee.io\/docs\/tutorial-docker-compose.html\">docker-compose automation<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u77e5\u9053\u6811\u8393\u6d3e\u5b89\u88c5Docker-compose\u6709\u70b9\u4e0d [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[357,249],"tags":[2901,1648,2900,2899],"class_list":["post-3354","post","type-post","status-publish","format-standard","hentry","category-zero2hero","category-technology","tag-compose","tag-docker","tag-docker-compose"],"_links":{"self":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/3354","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3354"}],"version-history":[{"count":1,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/3354\/revisions"}],"predecessor-version":[{"id":3355,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/3354\/revisions\/3355"}],"wp:attachment":[{"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zengqq.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}