我该如何为docker compose run指定一个docker compose文件?

3

我本来以为可以使用 docker-compose run -f <使用这个 Docker Compose 文件>,但是它却给了我一个使用错误。

我该怎么做呢?

以下是我的输出:

ls docker-compose-file.yml 
docker-compose-file.yml
me@host:~/work/my-dir$ docker-compose -f docker-compose-file.yml run                                                                              
Run a one-off command on a service.

For example:

    $ docker-compose run web python manage.py shell

By default, linked services will be started, unless they are already
running. If you do not want to start linked services, use
`docker-compose run --no-deps SERVICE COMMAND [ARGS...]`.

Usage:
    run [options] [-v VOLUME...] [-p PORT...] [-e KEY=VAL...] [-l KEY=VALUE...] [--]
        SERVICE [COMMAND] [ARGS...]

Options:
    -d, --detach          Detached mode: Run container in the background, print
                          new container name.
    --name NAME           Assign a name to the container
    --entrypoint CMD      Override the entrypoint of the image.
    -e KEY=VAL            Set an environment variable (can be used multiple times)
    -l, --label KEY=VAL   Add or override a label (can be used multiple times)
    -u, --user=""         Run as specified username or uid
    --no-deps             Don't start linked services.
    --rm                  Remove container after run. Ignored in detached mode.
    -p, --publish=[]      Publish a container's port(s) to the host
    --service-ports       Run command with the service's ports enabled and mapped
                          to the host.
    --use-aliases         Use the service's network aliases in the network(s) the
                          container connects to.
    -v, --volume=[]       Bind mount a volume (default [])
    -T                    Disable pseudo-tty allocation. By default `docker-compose run`
                          allocates a TTY.
    -w, --workdir=""      Working directory inside the container

docker-compose run启动一个基于docker-compose.yml文件中的某个容器的一次性容器,但是有不同的命令和其他几个差异。这意味着您需要将服务名称和命令都作为参数传递。您想要完成什么任务;您是否应该使用docker-compose up呢? - David Maze
1个回答

4

docker compose 有一些选项放在命令之前,还有一些选项放在命令之后。-f选项用于 docker compose,因此应该放在命令之前。

docker-compose -f <with this docker compose file> run

看看我的输出... - Snowcrash
你现在看到的输出是 docker-compose run 命令的选项,也就是在运行命令后可以指定的选项。如果你想了解在运行命令之前可以放置哪些选项,包括 -f 选项,请参考这里 https://docs.docker.com/compose/reference/。 - Hans Kilian
1
@Snowcrash,你是不是想使用up命令而不是runrun命令是用于对服务运行命令的。所以如果你想要这个功能,你需要同时指定服务名称和命令。 - Hans Kilian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接