{"id":4468,"date":"2018-12-04T23:54:59","date_gmt":"2018-12-04T23:54:59","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=4468"},"modified":"2018-12-11T04:17:34","modified_gmt":"2018-12-11T04:17:34","slug":"container-docker-compose-on-ubuntu-16-04","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/04\/container-docker-compose-on-ubuntu-16-04\/","title":{"rendered":"Container: Docker Compose on Ubuntu 16.04"},"content":{"rendered":"<p><a href=\"https:\/\/s24255.pcdn.co\/wp-content\/uploads\/2017\/06\/docker-compose-logo.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/s24255.pcdn.co\/wp-content\/uploads\/2017\/06\/docker-compose-logo-696x1226.png\" alt=\"docker compose logo\" width=\"696\" height=\"1226\" \/><\/a><\/p>\n<h3>What is Docker Compose<\/h3>\n<p><a href=\"https:\/\/docs.docker.com\/compose\/overview\/\">Docker Compose<\/a> is a tool for running multi-container Docker applications. To configure an application\u2019s services with Compose we use a configuration file, and then, executing a single command, it is possible to create and start all the services specified in the configuration.<\/p>\n<p>Docker Compose is useful for many different projects like:<\/p>\n<ul>\n<li>Development: with the Compose command line tools we create (and interact with) an isolated environment which will host the application being developed.<br \/>\nBy using the <a href=\"https:\/\/docs.docker.com\/compose\/compose-file\/\">Compose file<\/a>, developers document and configure all of the application\u2019s service dependencies.<\/li>\n<li>Automated testing: this use case requires an environment for running tests in. Compose provides a convenient way to manage isolated testing environments for a test suite. The full environment is defined in the Compose file.<\/li>\n<\/ul>\n<p>Docker Compose was made on the <a href=\"http:\/\/www.fig.sh\/\">Fig<\/a> source code, a community project now unused.<\/p>\n<p>In this tutorial we will see how to install Docker Compose on an Ubuntu 16.04 machine.<\/p>\n<h3>Install Docker<\/h3>\n<p>We need Docker in order to install Docker Compose. First, add the public key for the official Docker repository:<\/p>\n<p>$ curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo apt-key add-<\/p>\n<p>Next, add the Docker repository to apt sources list:<\/p>\n<p>$ sudo add-apt-repository &#8220;deb [arch=amd64] https:\/\/download.docker.com\/linux\/ubuntu $(lsb_release -cs) stable&#8221;<\/p>\n<p>Update the packages database and install Docker with apt:<\/p>\n<p>$ sudo apt-get update<br \/>\n$ sudo apt install docker-ce<\/p>\n<p>At the end of the installation process, the Docker daemon should be started and enabled to load at boot time. We can check its status with the following command:<\/p>\n<p>$ sudo systemctl status docker<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p>\u25cf docker.service &#8211; Docker Application Container Engine<br \/>\nLoaded: loaded (\/lib\/systemd\/system\/docker.service; enabled; vendor preset: enabled)<br \/>\nActive: active (running)<\/p>\n<h3>Install Docker Compose<\/h3>\n<p>At this point it is possible to install Docker Compose. Download the current release by executing the following command:<\/p>\n<p># curl -L https:\/\/github.com\/docker\/compose\/releases\/download\/1.14.0\/docker-compose-`uname -s`-`uname -m` &gt; \/usr\/local\/bin\/docker-compose<\/p>\n<p>Make the downloaded binary executable:<\/p>\n<p># chmod +x \/usr\/local\/bin\/docker-compose<\/p>\n<p>Check the Docker Compose version:<\/p>\n<p>$ docker-compose -v<\/p>\n<p>The output should be something like this:<\/p>\n<p>docker-compose version 1.14.0, build c7bdf9e<\/p>\n<h3>Testing Docker Compose<\/h3>\n<p>The Docker Hub includes a Hello World image for demonstration purposes, illustrating the configuration required to run a container with Docker Compose.<\/p>\n<p>Create a new directory and move into it:<\/p>\n<p>$ mkdir hello-world<br \/>\n$ cd hello-world<\/p>\n<p>Create a new YAML file:<\/p>\n<p>$ $EDITOR docker-compose.yml<\/p>\n<p>In this file paste the following content:<\/p>\n<p>unixmen-compose-test:<br \/>\nimage: hello-world<\/p>\n<p><em>Note: the first line is used as part of the container name.<\/em><\/p>\n<p>Save and exit.<\/p>\n<h4>Run the container<\/h4>\n<p>Next, execute the following command in the hello-world directory:<\/p>\n<p>$ sudo docker-compose up<\/p>\n<p>If everything is correct, this should be the output shown by Compose:<\/p>\n<p>Pulling unixmen-compose-test (hello-world:latest)&#8230;<br \/>\nlatest: Pulling from library\/hello-world<br \/>\nb04784fba78d: Pull complete<br \/>\nDigest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f<br \/>\nStatus: Downloaded newer image for hello-world:latest<br \/>\nCreating helloworld_unixmen-compose-test_1 &#8230;<br \/>\nCreating helloworld_unixmen-compose-test_1 &#8230; done<br \/>\nAttaching to helloworld_unixmen-compose-test_1<br \/>\nunixmen-compose-test_1 |<br \/>\nunixmen-compose-test_1 | Hello from Docker!<br \/>\nunixmen-compose-test_1 | This message shows that your installation appears to be working correctly.<br \/>\nunixmen-compose-test_1 |<br \/>\nunixmen-compose-test_1 | To generate this message, Docker took the following steps:<br \/>\nunixmen-compose-test_1 | 1. The Docker client contacted the Docker daemon.<br \/>\nunixmen-compose-test_1 | 2. The Docker daemon pulled the &#8220;hello-world&#8221; image from the Docker Hub.<br \/>\nunixmen-compose-test_1 | 3. The Docker daemon created a new container from that image which runs the<br \/>\nunixmen-compose-test_1 | executable that produces the output you are currently reading.<br \/>\nunixmen-compose-test_1 | 4. The Docker daemon streamed that output to the Docker client, which sent it<br \/>\nunixmen-compose-test_1 | to your terminal.<br \/>\nunixmen-compose-test_1 |<br \/>\nunixmen-compose-test_1 | To try something more ambitious, you can run an Ubuntu container with:<br \/>\nunixmen-compose-test_1 | $ docker run -it ubuntu bash<br \/>\nunixmen-compose-test_1 |<br \/>\nunixmen-compose-test_1 | Share images, automate workflows, and more with a free Docker ID:<br \/>\nunixmen-compose-test_1 | https:\/\/cloud.docker.com\/<br \/>\nunixmen-compose-test_1 |<br \/>\nunixmen-compose-test_1 | For more examples and ideas, visit:<br \/>\nunixmen-compose-test_1 | https:\/\/docs.docker.com\/engine\/userguide\/<br \/>\nunixmen-compose-test_1 |<br \/>\nhelloworld_unixmen-compose-test_1 exited with code 0<\/p>\n<p>Docker containers only run as long as the command is active, so the container will stop when the test finishes running.<\/p>\n<h3>Conclusion<\/h3>\n<p>This concludes the tutorial about the installation of Docker Compose on an Ubuntu 16.04 machine. We have also seen how to create a simple project through the Compose file in YAML format.<\/p>\n<p><a href=\"https:\/\/www.unixmen.com\/container-docker-compose-ubuntu-16-04\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Docker Compose Docker Compose is a tool for running multi-container Docker applications. To configure an application\u2019s services with Compose we use a configuration file, and then, executing a single command, it is possible to create and start all the services specified in the configuration. Docker Compose is useful for many different projects like: &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/04\/container-docker-compose-on-ubuntu-16-04\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Container: Docker Compose on Ubuntu 16.04&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4468","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/4468","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=4468"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/4468\/revisions"}],"predecessor-version":[{"id":5352,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/4468\/revisions\/5352"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=4468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=4468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=4468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}