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

2020-09-22 20:55:34 +08:00
 css3

常用的 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

然后想 buildup 的命令如下:

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

报错(我传的 serviceei ,这变成 build 了😳):

ERROR: No such service: build

那么问题来了,这个是不支持一条命令就能够 build 带参的 buildup

3028 次点击
所在节点    Docker
8 条回复
powerfulyang
2020-09-22 21:33:43 +08:00
--force-recreate 为什么不看看文档呢
powerfulyang
2020-09-22 21:35:42 +08:00
我的错😩我是瞎子
cheng6563
2020-09-22 21:37:42 +08:00
是不是版本问题,3 指的是 3.0 你看 3.1 和之后的版本有没有这参数
powerfulyang
2020-09-22 21:40:16 +08:00
是--build
jakezh
2020-09-22 21:48:57 +08:00
# docker-compose.yml
version: "3"

services:
ei:
build:
context: .
dockerfile: Dockerfile
args:
NODE_VERSION:test
css3
2020-09-22 22:01:34 +08:00
@powerfulyang 不行的,试过了
css3
2020-09-22 22:02:44 +08:00
@jakezh 要 build 的时候命令行传值,不是写死在 cocompose
css3
2020-09-23 10:02:44 +08:00
@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...]

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/709549

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX