跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • docker-copmose build 带参数的镜像,并启动容器的命令是什么?
未分類
22 9 月 2020

docker-copmose build 带参数的镜像,并启动容器的命令是什么?

docker-copmose build 带参数的镜像,并启动容器的命令是什么?

資深大佬 : css3 4

常用的 docker-compose build 镜像并启动的命令是

docker-compose up -d --build 

今天 build 一个 Dockerfile 中带参的镜像并启动,发现死活不行?是不支持吗?

docker-compose.yml

# docker-compose.yml version: "3"  services:   ei:     build:       context: .       dockerfile: Dockerfile       args:         - NODE_VERSION 

Dockerfile

# Dockerfile ARG NODE_VERSION  FROM node:$NODE_VERSION  RUN echo "-> $NODE_VERSION" 

尝试了单独 build 镜像,是能 build 的镜像的

docker-compose build --build-arg NODE_VERSION=test ei 

然后想 build 并 up 的命令如下:

docker-compose up -d build --build-arg NODE_VERSION=test ei 

报错(我传的 service 是 ei ,这变成 build 了

大佬有話說 (8)

  • 資深大佬 : powerfulyang

    –force-recreate 为什么不看看文档呢

  • 資深大佬 : powerfulyang

    我的错

  • 資深大佬 : cheng6563

    是不是版本问题,3 指的是 3.0 你看 3.1 和之后的版本有没有这参数

  • 資深大佬 : powerfulyang

    是–build

  • 資深大佬 : jakezh

    # docker-compose.yml
    version: “3”

    services:
    ei:
    build:
    context: .
    dockerfile: Dockerfile
    args:
    NODE_VERSION:test

  • 主 資深大佬 : css3

    @powerfulyang 不行的,试过了

  • 主 資深大佬 : css3

    @jakezh 要 build 的时候命令行传值,不是写死在 cocompose

  • 主 資深大佬 : css3

    @powerfulyang
    用
    docker-compose up -d –build –build-arg NODE_VERSION=test ei

    直接弹-h 选项
    Builds, (re)creates, starts, and attaches to containers for a service.

    Unless they are already running, this command also starts any linked services.

    The `docker-compose up` command aggregates the output of each container. When
    the command exits, all containers are stopped. Running `docker-compose up -d`
    starts the containers in the background and leaves them running.

    If there are existing containers for a service, and the service’s configuration
    or image was changed after the container’s creation, `docker-compose up` picks
    up the changes by stopping and recreating the containers (preserving mounted
    volumes). To prevent Compose from picking up changes, use the `–no-recreate`
    flag.

    If you want to force Compose to stop and recreate all containers, use the
    `–force-recreate` flag.

    Usage: up [options] [–scale SERVICE=NUM…] [SERVICE…]

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具