常用的 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
了😳):
ERROR: No such service: build
那么问题来了,这个是不支持一条命令就能够 build
带参的 build
加 up
吗
1
powerfulyang 2020-09-22 21:33:43 +08:00 via iPhone
--force-recreate 为什么不看看文档呢
|
2
powerfulyang 2020-09-22 21:35:42 +08:00 via iPhone
我的错😩我是瞎子
|
3
cheng6563 2020-09-22 21:37:42 +08:00 via Android
是不是版本问题,3 指的是 3.0 你看 3.1 和之后的版本有没有这参数
|
4
powerfulyang 2020-09-22 21:40:16 +08:00 via iPhone
是--build
|
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 |
6
css3 OP @powerfulyang 不行的,试过了
|
8
css3 OP @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...] |