Docker-compose: close ports after SIGTERM

I’m using Docker and Docker Compose for my development environment.

When I switch between projects, I usually have quite some pain because I receive a PORT ALREADY IN USE error.

  • Docker disk memory : can I remove intermediate images?
  • How to map docker images to a dockerfile?
  • How to exclude some paths when mounting the volume?
  • Running IBM DOORS in a docker container
  • WSO2 : how to download products in a Dockerfile?
  • About workaround on bug of runc
  • If I do docker-compose up (which makes my rails server start), is Ctrl+C the correct way to terminate this container?

    Here’s my docker-compose.yml file:

    db:
      image: postgres
      ports:
        - "5432"
    web:
      build: .
      command: bundle exec rails s -p 3000 -b '0.0.0.0'
      volumes:
        - .:/myapp
      ports:
        - "3000:3000"
      links:
        - db
    

    Sometimes, I simply have to delete ./tmp/pids/server.pid, but sometimes I have to kill -9 some process.

    Here’s for example what ps -edf | grep docker outputs:

    root       742     1  0 Jul18 ?        00:01:11 /usr/bin/docker -d -H fd://
    root     22341   742  0 Jul21 ?        00:00:00 docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 32781 -container-ip 172.17.0.48 -container-port 5432
    root     22510   742  0 Jul21 ?        00:00:00 docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3030 -container-ip 172.17.0.49 -container-port 3030
    root     28766   742  0 Jul21 ?        00:00:00 docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 32783 -container-ip 172.17.0.57 -container-port 5432
    root     28886   742  0 Jul21 ?        00:00:00 docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3000 -container-ip 172.17.0.58 -container-port 3000
    

    Am I doing something wrong?

  • Fail to build MongoDB replcaset with Auth on Swarm
  • Docker Update Secrets via API
  • Do I need my own server if I move my Elastic Beanstalk app to use Docker?
  • Is it possible to run Telegraf in Docker (and get accurate metrics)?
  • Google cloud sdks doesn't start preview for Docker image Mac OS
  • Gitlab CI runner unabled to shared build sources on docker executor
  • One Solution collect form web for “Docker-compose: close ports after SIGTERM”

    I would launch the container as a background process with docker-compose up -d. Then later you can do a shutdown with docker-compose stop in a clean way.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.