JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Docker >

Differences between Docker and Docker Compose

Author:JIYIK Last Updated:2025/03/24 Views:

Both docker and docker composedocker run Docker containers. The two Docker constructs are comparable, but that's about it.

This article will discuss docker composethe main differences between docker and .


Differences between Docker and Docker Compose

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

The second key difference is that docker-compose can configure and operate multiple containers, while docker can only start one container at a time.

Run the Docker CLI

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

Sample code:

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

At the same time, we can use the docker-compose CLI to manage multi-container applications. It also moves many of the options you would enter on the docker run CLI into the docker-compose.yml file for easy reuse.

It acts as a staging area on top of the same Docker API used by docker, allowing us to leverage docker commands and a host of shell scripts to accomplish anything that docker compose can accomplish.

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

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Recreate the container from the new image using Docker-Compose

Publish Date:2025/03/24 Views:178 Category:Docker

As we develop our applications, we often make changes or add more features to make the application more effective for the different users who interact with the application. When using Docker, we need to ensure that the changes or features w

Exposing multiple ports in a Docker container

Publish Date:2025/03/24 Views:186 Category:Docker

There are different types of communication on the Internet, the most common ones include file transfers, sending emails, and serving web pages. To make this communication possible, we make use of port numbers that help identify the type of

Using Docker network host commands

Publish Date:2025/03/24 Views:51 Category:Docker

Docker containers work by leveraging network drivers that are created during the installation of Docker. The default drivers available to us include bridge and host networking. When we create containers without specifying a network, they ar

Clear Docker container logs

Publish Date:2025/03/24 Views:192 Category:Docker

Logs are information recorded by the application when a specific event or state occurs. They help us monitor the application and take necessary actions. For example, when we deploy an application to a production environment, logs can help u

Docker daemon log location

Publish Date:2025/03/24 Views:65 Category:Docker

The Docker daemon provides essential information about the general state of your microservices architecture. Unfortunately, container-centric logging techniques allow you to collect relevant data from your services but provide little inform

Difference between COPY and ADD commands in Dockerfile

Publish Date:2025/03/24 Views:140 Category:Docker

A Dockerfile is a text document that contains all the commands used to build a Docker image. Recently, we have seen Docker being widely used as the default tool for managing configurations and automating deployments. Advanced features such

The --rm flag in Docker

Publish Date:2025/03/24 Views:151 Category:Docker

Typically, when most developers start using docker, after going through all the processes of pulling images, building them, and running containers, removing a container defeats the purpose of doing so. However, for experienced developers, t

Setting environment variables in Docker

Publish Date:2025/03/24 Views:188 Category:Docker

Environment variables are used to add additional configuration or metadata to aid in the development of an application, and can exist in different forms. For example, when developing a Java application, we usually set an environment variabl

在 Linux 中托管 Docker Internal

Publish Date:2023/04/18 Views:221 Category:Docker

Docker 允许开发人员通过将应用程序包装在称为容器的标准化单元中来高效地构建、测试和部署应用程序。 在使用 Docker 容器时,您可能会遇到需要将容器与主机连接的场景。

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial