迹忆客 EN >

当前位置:主页 > 学无止境 > 操作系统 > Docker >

Docker 和 Docker Compose 之间的区别

作者:迹忆客 最近更新:2023/04/17 浏览次数:

docker 和 docker compose 都可以用来运行 Docker 容器。 这两个 Docker 结构具有可比性,但仅限于此。

本文将讨论 docker 和 docker compose 之间的主要区别。


Docker 和 Docker Compose 之间的区别

docker 和 docker compose 之间的关键区别在于 docker 仅依赖命令行 (CLI),而 docker compose 从 YAML 文件接收配置信息。

第二个关键区别是 docker-compose 可以配置和操作多个容器,而 docker 只能同时启动一个容器。

运行 Docker CLI

Docker 引擎通过 docker CLI 管理各个容器。 要联系 Docker 守护程序 API,请使用客户端命令行。

示例代码:

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

同时,我们可以使用 docker-compose CLI 来管理多容器应用程序。 它还将您将在 docker run CLI 上输入的许多选项移动到 docker-compose.yml 文件中,以便于重用。

它作为 docker 使用的相同 Docker API 之上的暂存区,允许我们利用 docker 命令和大量 shell 脚本来完成 docker compose 可以完成的任何事情。

YAML 文件:

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

示例代码:

$ docker-compose up -d --rm

转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处

本文地址:

相关文章

Solution to incorrect access log time when deploying Nginx in Docker

发布时间:2025/03/26 浏览次数:165 分类:Docker

In the process of operating the website, I never took the logs too seriously. Although logging was turned on, I never analyzed the logs carefully. Today, when I looked at the logs on a whim, I found that the recorded time was 8 hours less t

Docker deploys nginx php application

发布时间:2025/03/26 浏览次数:131 分类:Docker

I'm learning docker recently. I'm learning by building an nginx+php development environment example. Here I record the build process. First, give a docker-compose.yml deployment configuration file version: '3' services: nginx: container_nam

How to use Docker to image a Node.js web application

发布时间:2025/03/26 浏览次数:107 分类:Docker

Docker is a containerization platform that simplifies the packaging and execution of applications. Containers run as independent processes with their own file systems, but share the kernel of their host machine. Docker has attracted much at

Start a Bash terminal in a new Docker container

发布时间:2025/03/26 浏览次数:97 分类:Docker

Docker containers are a standard unit for packaging all the dependencies of an application, allowing us to easily run them in any environment. Containers have become very popular recently, and most developers now rely heavily on containers

Passing environment variables to containers in Docker

发布时间:2025/03/26 浏览次数:124 分类:Docker

This article will introduce how to pass environment variables to containers in Docker. Passing environment variables to containers in Docker using the -e and tags -env We will first see how to create environment variables and pass them to t

Install Docker using Homebrew

发布时间:2025/03/26 浏览次数:202 分类:Docker

There is no doubt that Docker containers have revolutionized the way we develop and deploy applications. They provide developers with the ability to package applications and dependencies in an isolated environment. Recently, we've seen wide

Enforce clean build of images in Docker

发布时间:2025/03/26 浏览次数:87 分类:Docker

This article discusses and demonstrates how to enforce clean builds of images in Docker. Building images in Docker We will use a simple Flask application to demonstrate this concept. my-app Create a app.py simple application named in the ho

Running a Docker instance from a Dockerfile

发布时间:2025/03/26 浏览次数:140 分类:Docker

Docker containers have undoubtedly become the standard unit for managing software and dependencies in different environments. When using real applications, you must create a docker file before building the container image of the application

扫一扫阅读全部技术教程

社交账号
  • https://www.github.com/onmpw
  • qq:1244347461

最新推荐

教程更新

热门标签

扫码一下
查看教程更方便