docker-copmose build 带参数的镜像,并启动容器的命令是什么? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
css3
V2EX    Docker

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

  •  
  •   css3 2020-09-22 20:55:34 +08:00 3451 次点击
    这是一个创建于 1913 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    8 条回复    2020-09-23 10:02:44 +08:00
    powerfulyang
        1
    powerfulyang  
       2020-09-22 21:33:43 +08:00 via iPhone
    --force-recreate 为什么不看看文档呢
    powerfulyang
        2
    powerfulyang  
       2020-09-22 21:35:42 +08:00 via iPhone
    我的错我是瞎子
    cheng6563
        3
    cheng6563  
       2020-09-22 21:37:42 +08:00 via Android
    是不是版本问题,3 指的是 3.0 你看 3.1 和之后的版本有没有这参数
    powerfulyang
        4
    powerfulyang  
       2020-09-22 21:40:16 +08:00 via iPhone
    是--build
    jakezh
        5
    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
        6
    css3  
    OP
    &bsp;  2020-09-22 22:01:34 +08:00 via iPhone
    @powerfulyang 不行的,试过了
    css3
        7
    css3  
    OP
       2020-09-22 22:02:44 +08:00 via iPhone
    @jakezh 要 build 的时候命令行传值,不是写死在 cocompose
    css3
        8
    css3  
    OP
       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...]
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     911 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 20:29 PVG 04:29 LAX 12:29 JFK 15:29
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86