Lab #10: stop Command

The docker-compose stop command help us to stop containers in service.

Pre-requisite:

Tested Infrastructure

Platform Number of Instance Reading Time
Play with Docker 1 5 min

Pre-requisite

Assignment

Create a docker-compose.yml file

version: '3.1'
services:
  #Nginx Service
   webserver:
     image: nginx:alpine
     container_name: nginx
     restart: unless-stopped
     ports:
       - "80:80"
       - "443:443"
   dbserver:
      image: mysql:5.7
      container_name: Mysqldb
      restart: unless-stopped
      ports:
        - "3306:3306"
      environment:
        MYSQL_ROOT_PASSWORD: Pa$$w0rd
        MYSQL_USER: test
        MYSQL_PASSWORD: Pa$$w0rd123
        MYSQL_DATABASE: test 
      volumes:
        - db_data:/var/lib/mysql
volumes:
  db_data:

Bringup the containers

$ docker-compose up -d

Checking container status

$ docker-compose ps
  Name                Command             State                    Ports                  
------------------------------------------------------------------------------------------
Mysqldb     docker-entrypoint.sh mysqld   Up      0.0.0.0:3306->3306/tcp, 33060/tcp       
nginx       nginx -g daemon off;          Up      0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp

Stop the container service

$ docker-compose stop
Stopping webserver ... done
Stopping Mysqldb   ... done

Listout the services

$ docker-compose ps --services
webserver
dbserver

Stoping a single service

$ docker-compose stop webserver
Stopping webserver ... done

Contributor

Savio Mathew

Next » Lab #11: Start Command