Everything You Need to Know About Docker & Docker Compose to Get Started

What is Docker Compose?

Docker is known for its use of OS-level virtualization and for the container system that employs to make creating, deploying and running applications much easier for developers.

While learning the basics of Docker, you may have come across the creation of simple applications that work autonomously, not depending, for example, on external data sources or on certain services. In practice, such applications are rare. Real projects usually involve a whole set of collaborative applications.

Docker Compose technology, if we describe it in a simplified way, allows, with the help of one command, to start many services.

So, Docker Compose is software tool used for defining and running multi-container Docker applications.

Difference Between Docker and Docker Compose

Docker is used to manage the individual containers (services) that make up an application.

Docker Compose is used to manage multiple containers that are part of an application at the same time. This tool offers the same features as Docker, but allows you to work with more complex applications.

Docker Compose Use Cases

  • Automated testing environments.

An important part of any Deployment or Integration process is the automated test suite.

Compose supports automated testing, which is an essential part of CI/CD and provides a convenient and easy way to create and destroy isolated testing environments for your testing. Developers can define and configure the environment needed for running automated end-to-end testing  in just a few commands using the appropriate Docker Compose file.

  • Single host deployments.

In Docker Compose, containers are designed to run on a single host as they have traditionally been focused on development and testing workflows.

  • Development Environments.

Compose is a fast and simple way of starting projects as it can quickly spin up new isolated development environments. The software documents and configures all the application’s service dependencies (including databases, caches, web service APIs, etc.). It allows you to create and start one or multiple containers for each dependency using a single command.

  • Release notes.

You can see a detailed list of changes for past and current releases of Docker Compose, refer to the Changelog.

What features make Docker Compose so effective?

  • Multiple isolated environments on a single host
  • Preserve volume data when containers are created
  • Only recreate containers that have changed
  • Variables and moving a composition between environments

We have covered the basics of working with Docker Compose technology, the knowledge of which will allow you to use this technology and, if you desire, begin to study it in more depth.

Do you use Docker Compose in your projects?

Overwhelmed by this content? Reach out with your next big idea and we’ll take care of all the technical details so you can focus on the bigger picture.

Minimal Node.js Development Environment Using Docker Compose

Quick and painless setup of a basic local development environment for Node.js using docker-compose.

This is a quick tutorial on how to get a Node.js Docker container up and running for local development.

This approach does NOT require a Dockerfile and solves infamous insidious server response issues.  No more “localhost didn’t send any data” or “ERR_EMPTY_RESPONSE” or “127.0.0.1 didn’t send any data”.

You will need Docker Community Edition installed and running (aka Docker desktop) and exactly two files to fire up a Node.js app – “docker-compose.yml” and “app.js”.

local development environment for Node.js using docker-compose

docker-compose.yml

version: "3"
services:
    app:
        image: node:alpine
        volumes:
          - .:/app
        working_dir: /app
        ports:
          - 80:80
        command: node app.js

app.js

const http = require('http');
const hostname = '0.0.0.0';
const port = 80;

const server = http.createServer((req, res) => {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('Live long and prosper!\n');
});

server.listen(port, hostname, () => {
    console.log(`Server running at http://${hostname}:${port}/`);
});

Then navigate to the newly-created folder using the console and type: “docker-compose up -d”

That’s all.
Now you can open your browser and access your app at “http://localhost

Отладка. Будет убрана потом