Turning down a web server from a running container via bash

I have the following docker-compose.yml to start a webserver with PHP.

version: "2.0"

services:

  nginx:
    image: nginx
    ports:
      - "8000:80"
    volumes:
      - ./web:/web
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf

  php:
    image: php:${PHP_VERSION}-fpm
    volumes:
      - ./web:/web

After running docker-compose up, I can access my website perfectly at http://localhost:8000. But if I then access the nginx container, with:

$ docker-compose run nginx bash

and within the container I run:

$ service nginx stop

I still can see the website http://localhost:8000 being displayed in the browser.

How can it be that after stopping the server in the container, the website is still being delivered?

1 answer

  • answered 2018-04-14 15:53 psrcek

    The docker-compose run command starts a new container, you're stopping nginx in that new container, what you want is docker attach nginx

    The documentation is located here.