简体   繁体   English

将docker-compose.yml改造为docker运行

[英]Transform docker-compose.yml to docker run

I'm newer in docker and I don't understand how to transform this docker-compose.yml:我是 docker 的新人,我不明白如何转换这个 docker-compose.yml:

version: '3'
services:
  php:
    build: .
    volumes:
      - "./:/var/www/html:ro"
      - "./:/var/log/php"

Into a simple docker command in one line (if possible).在一行中输入简单的 docker 命令(如果可能)。 I've tried this: docker build -t mstp2html --mount source=./,target=/var/www/html,ro --mount source=./,target=/var/log/php -f-.我试过这个: docker build -t mstp2html --mount source=./,target=/var/www/html,ro --mount source=./,target=/var/log/php -f-. and this: docker run --name mstp2html --mount source=./,target=/var/www/html,ro --mount source=./,target=/var/log/php./Dockerfile和这个: docker run --name mstp2html --mount source=./,target=/var/www/html,ro --mount source=./,target=/var/log/php./Dockerfile

But don't work.但是不要工作。 What I've missing?我错过了什么?

You are mixing two concepts:您正在混合两个概念:

  • build: the stage in which the docker image is created, but it does not have relation on how it will run build:创建 docker 镜像的阶段,但与它将如何运行无关
  • run: the stage in which you run a docker container based on an existing docker image.运行:您基于现有 docker 图像运行 docker 容器的阶段。 In this stage, you can define options such as volumes.在此阶段,您可以定义卷等选项。

In order for your example to work, you would need to split that into two stages:为了使您的示例正常工作,您需要将其分为两个阶段:

  1. Build the docker image:构建 docker 镜像:
docker build -t mstp2html_image .
  1. Run a container from the image and mount the volumes you want to:从图像运行一个容器并安装你想要的卷:
docker run --name mstp2html --mount type=bind,source="$(pwd)",target=/var/www/html,ro --mount type=bind,source="$(pwd)",target=/var/log/php mstp2html_image

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM