Difference Between Docker and Docker Compose

Difference Between Docker and Docker Compose

Both docker and docker compose can be used to run a Docker container. These two Docker structures are comparable, but only to that point.

This article will discuss the main differences between docker and docker compose.

Difference Between Docker and Docker Compose

The critical distinction between docker and docker compose is that docker relies solely on the command line (CLI), whereas docker compose receives configuration information from a YAML file.

The second key distinction is that whereas docker-compose can configure and operate several containers, docker can only start a single container simultaneously.

Running Docker CLI

A Docker engine manages individual containers through the docker CLI. To contact the Docker daemon API, use the client command line.

Example Code:

docker run -d --rm --name=my-website --cpus=1.5 --memory=1048m -p 80:80 -v /usr/share/nginx/html/ nginx:latest

Meanwhile, we can use the docker-compose CLI to manage a multi-container application. It also moves many options you would enter on the docker run CLI into the docker-compose.yml file for easier reuse.

It functions as a staging area on top of the same Docker API used by docker, allowing us to utilize docker commands and a lot of shell scripting to accomplish anything docker compose can.

YAML file:

version: '3.9'
services:
  nginx-test-service:
    container_name: sample-website
    image: nginx:latest
    cpus: 1.5
    mem_limit: 1024m
    ports:
      - "80:80"
    volumes:
      /usr/share/nginx/html

Example Code:

docker-compose up -d --rm
Marion Paul Kenneth Mendoza avatar Marion Paul Kenneth Mendoza avatar

Marion specializes in anything Microsoft-related and always tries to work and apply code in an IT infrastructure.

LinkedIn

Related Article - Docker Compose