2

I have several containers which are described in a docker-compose-<service>.yaml file each, and which I start with

docker-compose -f docker-compose-<service>.yaml up -d

I then see via docker ps the container running.

I expected that I could stop that container via

docker-compose -f docker-compose-<service>.yaml down

The container is however not stopped. Neither it is when I use the comane above with stop instead of down.

Doing a docker kill <service> stops the container.

My question: since all my services started with docker-compose are effectively one container for each docker-compose-<service>.yaml file, can I use the bare docker command to stop it?

Or more generally speaking: is docker-compose simply a helper for underlying docker commands which means that using docker is always safe (from a "consistency in using different commands" perspective)?

WoJ
  • 27,165
  • 48
  • 180
  • 345
  • You can definitely stop a compose container using `docker stop `. But why do you have one compose file per image? Why use compose at all in this case? – Justin Lessard Dec 03 '19 at 16:16
  • 1
    @JustinLessard: several reasons: 1) because it is easier to write configurations in the docker-compose format rather than dragging a `docker run ...` on several lines, 2) it makes starting /stopping them easier when you have 50 or 60 containers, etc. The alternative would be kubernetes but it is way to big form my home setup – WoJ Dec 03 '19 at 16:38
  • In this case, I recommend https://github.com/rancher/k3s, tested and approved in local, dev and prod env. But it is using 'containerd' by default. It is possible to use docker instead. – GoA Oz Dec 04 '19 at 10:50
  • That's weird... Can you post your `docker-compose-.yml` file ? It should definitely work with the `docker-compose stop` command. – Marc ABOUCHACRA Dec 09 '19 at 10:14

1 Answers1

0

My question: since all my services started with docker-compose are effectively one container for each docker-compose-.yaml file, can I use the bare docker command to stop it?

Actually docker-compose is using docker engine, you can try locally:

ex: docker-compose.yaml:

version: "3"
services:
  # Database
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    networks:
      - wpsite
  # phpmyadmin
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - '9090:80'
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: wordpress
    networks:
      - wpsite
networks:
  wpsite:

enter image description here You can now interact with them thought docker engine if needed: enter image description here

More globally docker-compose is a kind of orchestrater ( I prefer the terme of composer), if you need a to define container stack, dependent each others (like the previous example phpmyadmin/mysql) it is perfect to test in dev environment. In my point of view to have a better resilience, HA, service management... of containers stack in production environment, you strongly need to consider the implementation of a real orchestrater such as docker-swarm, kubernetes, openshift.... Here some documentation to explain the difference: https://linuxhint.com/docker_compose_vs_docker_swarm/

You can also see: What is the difference between `docker-compose build` and `docker build`?

GoA Oz
  • 328
  • 1
  • 13