docker-compose up for only certain containers

前端 未结 7 630
盖世英雄少女心
盖世英雄少女心 2020-12-22 20:31

I have a docker-compose.yml which contain several containers. Three of them are for my app (client, server and database) and the rest are for various dev tools

7条回答
  •  清歌不尽
    2020-12-22 20:49

    To start a particular service defined in your docker-compose file. for example if your have a docker-compose.yml

    sudo docker-compose start db  
    

    given a compose file like as:

    version: '3.3'
    
    services:
       db:
         image: mysql:5.7
         ports:
           - "3306:3306"
         volumes:
           - ./db_data:/var/lib/mysql
         restart: always
         environment:
           MYSQL_ROOT_PASSWORD: yourPassword
           MYSQL_DATABASE: wordpress
           MYSQL_USER: wordpress
           MYSQL_PASSWORD: yourPassword
    
       wordpress:
         depends_on:
           - db
         image: wordpress:latest
         ports:
           - "80:80"
         volumes:
           - ./l3html:/var/www/html
         restart: always
         environment:
           WORDPRESS_DB_HOST: db:3306
           WORDPRESS_DB_USER: wordpress
           WORDPRESS_DB_PASSWORD: yourPassword
    volumes:
        db_data:
        l3html:
    

    Some times you want to start mySQL only (sometimes you just want to populate a database) before you start your entire suite.

提交回复
热议问题