{"id":3874,"date":"2021-01-27T19:16:20","date_gmt":"2021-01-27T19:16:20","guid":{"rendered":"https:\/\/linuxways.net\/?p=3874"},"modified":"2021-01-27T19:16:23","modified_gmt":"2021-01-27T19:16:23","slug":"how-to-install-docker-compose-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-docker-compose-on-ubuntu-20-04\/","title":{"rendered":"How to Install Docker Compose on Ubuntu 20.04"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>Docker Compose is known as a command-line tool for running multiple containers on Docker defined. It uses the compose file in YAML format to configure the necessary resources for containers such as volumes, networking, and so on.<\/p>\n<p>You can use Docker compose to define an isolated environment for containerized applications that can be run on any system.<\/p>\n<p>This tutorial will explain the detail of installing Docker Compose on Ubuntu 20.04 LTS and explore some simple examples of using Docker Compose as well.<\/p>\n<h2>Prerequisites<\/h2>\n<p>Before installing Docker Compose, you have to install Docker on your Ubuntu 20.04 machine first.<\/p>\n<p>Updating the packages repository and installing the dependent packages by running:<\/p>\n<pre>$ sudo apt update<\/pre>\n<pre>$ sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common<\/pre>\n<p>Then, adding the Docker apt-repository to your OS:<\/p>\n<pre>$ curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo apt-key add -<\/pre>\n<pre>$ sudo add-apt-repository \"deb [arch=amd64] https:\/\/download.docker.com\/linux\/ubuntu $(lsb_release -cs) stable\"<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1577\" height=\"614\" class=\"wp-image-3875\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-461.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-461.png 1577w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-461-300x117.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-461-1024x399.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-461-768x299.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-461-1536x598.png 1536w\" sizes=\"auto, (max-width: 1577px) 100vw, 1577px\" \/><\/p>\n<p>Once the Docker repository was added, you can install the Docker by running:<\/p>\n<pre>$ sudo apt update<\/pre>\n<pre>$ sudo apt install docker-ce<\/pre>\n<p>Verifying that Docker was successfully installed and started automatically:<\/p>\n<pre>$ sudo systemctl status docker<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1578\" height=\"441\" class=\"wp-image-3876\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-462.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-462.png 1578w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-462-300x84.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-462-1024x286.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-462-768x215.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-462-1536x429.png 1536w\" sizes=\"auto, (max-width: 1578px) 100vw, 1578px\" \/><\/p>\n<h2>Installing Docker Compose<\/h2>\n<p>At the time of this writing, the latest version of Docker Compose is 1.27.4. To download the docker-compose file to your Ubuntu 20.04 machine, running:<\/p>\n<pre>$ sudo curl -L \"https:\/\/github.com\/docker\/compose\/releases\/download\/1.27.4\/docker-compose-$(uname -s)-$(uname -m)\" -o \/usr\/local\/bin\/docker-compose<\/pre>\n<p>Then, grant the execute permission for docker-compose file:<\/p>\n<pre>$ sudo chmod +x \/usr\/local\/bin\/docker-compose<\/pre>\n<p>Verifying that the Docker Compose was successfully installed:<\/p>\n<pre>$ docker-compose --version<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1546\" height=\"398\" class=\"wp-image-3877\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-463.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-463.png 1546w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-463-300x77.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-463-1024x264.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-463-768x198.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-463-1536x395.png 1536w\" sizes=\"auto, (max-width: 1546px) 100vw, 1546px\" \/><\/p>\n<h2>A simple example of using Docker Compose<\/h2>\n<p>In this section, we\u2019re going to build an Nginx web server using Docker Compose:<\/p>\n<p>First, create a new folder called myapp then change directory to it:<\/p>\n<pre>$ mkdir myapp<\/pre>\n<pre>$ cd myapp<\/pre>\n<p>Then, using your favorite editor to create a compose file called docker-compose.yaml<\/p>\n<pre>$ vim docker-compose.yaml<\/pre>\n<pre>version: '3'\n\nservices:\n\nwebserver:\n\nimage: nginx:alpine\n\ncontainer_name: web_server\n\nrestart: unless-stopped\n\nports:\n\n- \"80:80\"\n\n- \"443:443\"\n\nnetworks:\n\n- app-network\n\nnetworks:\n\napp-network:\n\ndriver: bridge\n<\/pre>\n<p>In this compose file, we defined one service: webserver. It used docker image nginx:alpine from Docker Hub.<\/p>\n<p>In myapp directory, run the following command to start the application:<\/p>\n<pre>$ sudo docker-compose up<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1546\" height=\"540\" class=\"wp-image-3878\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-464.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-464.png 1546w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-464-300x105.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-464-1024x358.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-464-768x268.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-464-1536x537.png 1536w\" sizes=\"auto, (max-width: 1546px) 100vw, 1546px\" \/><\/p>\n<p>Open new terminal and using curl command to verify that webserver is running:<\/p>\n<pre>$ curl localhost:80<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1546\" height=\"632\" class=\"wp-image-3879\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-465.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-465.png 1546w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-465-300x123.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-465-1024x419.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-465-768x314.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-465-1536x628.png 1536w\" sizes=\"auto, (max-width: 1546px) 100vw, 1546px\" \/><\/p>\n<p>To list the running service, run:<\/p>\n<pre>$ sudo docker-compose ps<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1546\" height=\"188\" class=\"wp-image-3880\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-466.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-466.png 1546w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-466-300x36.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-466-1024x125.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-466-768x93.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/word-image-466-1536x187.png 1536w\" sizes=\"auto, (max-width: 1546px) 100vw, 1546px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>You\u2019ve successfully installed and tried running a simple Docker Compose example on your Ubuntu 20.04 LTS machine.<\/p>\n<p>If you have any concerns, feel free to leave your comment and let me know. Thank you!<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction Docker Compose is known as a command-line tool for running multiple containers on Docker defined. It uses the compose file in YAML format to configure the necessary&hellip;<\/p>","protected":false},"author":23,"featured_media":3883,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[160,100],"class_list":["post-3874","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-docker","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/3874","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=3874"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/3874\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/3883"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=3874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=3874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=3874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}