让 docker-compose up 只运行某些容器 [英] Get docker-compose up to only run certain containers

查看:106
本文介绍了让 docker-compose up 只运行某些容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我目前可以使用docker-compose up test",它只运行我的数据库和我的测试脚本.我希望能够对我们说 docker-compose up app" 或类似的东西,它可以运行除测试之外的所有内容.这样我就不会运行不必要的容器.我不确定是否有办法,但这就是我想知道的.如果可能的话,我很感激一些已经这样做的链接,我可以弄清楚其余的.基本上我可以只用一个命令运行某些容器而不运行其他容器.

So i currently can use "docker-compose up test" which only runs my database and my testing scripts. I want to be able to us say docker-compose up app" or something like that that runs everything besides testing. That way Im not running unnecessary containers. Im not sure if theres a way but thats what I was wondering. If possible Id appreciate some links to some that already do that and I can figure out the rest. Basically can I only run certain containers with a single command without running the others.

Yaml

version: '3'
services:
  webapp:
    build: ./literate-app 
    command: nodemon -e vue,js,css start.js
    depends_on:
      - postgres
    links:
      - postgres
    environment:
      - DB_HOST=postgres
    ports:
     - "3000:3000"
    networks:
      - literate-net


  server:
    build: ./readability-server
    command: nodemon -L --inspect=0.0.0.0:5555 server.js
    networks:
      - literate-net


  redis_db:
    image: redis:alpine
    networks:
      - literate-net


  postgres:
    restart: 'always'
    #image: 'bitnami/postgresql:latest'
    volumes:
     - /bitnami
    ports:
      - "5432:5432"
    networks:
      - literate-net
    environment:
      - "FILLA_DB_USER=my_user"
      - "FILLA_DB_PASSWORD=password123"
      - "FILLA_DB_DATABASE=my_database"
      - "POSTGRES_PASSWORD=password123"
    build: './database-creation'


  test: 
    image: node:latest
    build: ./test
    working_dir: /literate-app/test
    volumes:
      - .:/literate-app
    command:
      npm run mocha
    networks:
      - literate-net
    depends_on:
      - postgres
    environment:
      - DB_HOST=postgres


networks:
  literate-net:
    driver: bridge

我可以运行 docker-compose up 测试

I can run docker-compose up test

仅运行 postgres.虽然我希望能够运行我的应用程序而不必运行我的测试容器.

Which only runs the postgres. Though I'd like to be able to just run my app without having to run my testing container.

编辑

感谢@ideam 提供链接

Thanks to @ideam for the link

我能够创建一个额外的 yaml 文件来进行测试.对于那些不想查找它的人,只需像这样创建一个新的 yaml 文件

I was able to create an additional yaml file for just testing. For those that dont want to look it up simply create a new yaml file like so

docker-compose.dev.yml

docker-compose.dev.yml

将 dev 替换为你喜欢的任何东西,除了 override 这会导致 docker-compose up 自动运行,除非另有说明

replace dev with whatever you like besides override which causes docker-compose up to automatically run that unless otherwise specified

要运行新文件,只需调用

To run the new file simply call

docker-compose -f docker-compose.dev.yml up

docker-compose -f docker-compose.dev.yml up

-f 是选择要运行的特定文件的标志.您可以运行多个文件来设置不同的环境

The -f is a flag for selecting a certain file to run. You can run multiple files to have different enviornments set-up

感谢帮助

推荐答案

也许你想分享你的 docker-compose.yml 以获得比这更好的答案.

Maybe you want to share your docker-compose.yml for a better answer than this.

要重用 docker-compose 配置,请查看 https://docs.docker.com/compose/extends/#example-use-case 解释了多个配置文件的组合,以便为不同的用例(测试、生产等)重用配置

For reusing docker-compose configurations have a look at https://docs.docker.com/compose/extends/#example-use-case which explains the combination of multiple configuration files for reuse of configs for different use cases (test, production, etc.)

这篇关于让 docker-compose up 只运行某些容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆