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.

  • Unable to pull docker image with concourse - Verifying Checksum error
  • Cant load data onto Jupyter docker
  • Container command could not be invoked
  • Advantages of a Dockerfile
  • Jenkins deployment to docker swarm by using Ansible
  • Can Firewalld work with the Docker Overlay Network?
  • 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:

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

    Sometimes, I simply have to delete ./tmp/pids/, 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 -host-port 32781 -container-ip -container-port 5432
    root     22510   742  0 Jul21 ?        00:00:00 docker-proxy -proto tcp -host-ip -host-port 3030 -container-ip -container-port 3030
    root     28766   742  0 Jul21 ?        00:00:00 docker-proxy -proto tcp -host-ip -host-port 32783 -container-ip -container-port 5432
    root     28886   742  0 Jul21 ?        00:00:00 docker-proxy -proto tcp -host-ip -host-port 3000 -container-ip -container-port 3000

    Am I doing something wrong?

  • Installing specific version of docker
  • How to send http request from Docker to localhost or Virtual Machine
  • Cannot run shell script placed on volume inside Docker container
  • Running docker on read-only root file system
  • How do you get a VPC Endpoint to work in a Docker container?
  • Can't build docker package (docker-git) with makepkg
  • 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.