Port mappings are released immediately when containers are stopped or removed, allowing the ports to be reused by other containers or system services.
Port mappings to not seem to be released immediately when containers stop. They are released eventually, but in my testing it can take up to a few minutes for them to free.
OS X: version 10.11.4 (build: 15E65) Docker.app: version v1.11.0-beta9 Running diagnostic tests: [OK] docker-cli [OK] Moby booted [OK] driver.amd64-linux [OK] vmnetd [OK] osxfs [OK] db [OK] slirp [OK] menubar [OK] environment [OK] Docker [OK] VT-x Docker logs are being collected into /tmp/20160430-003412.tar.gz Most specific failure is: No error was detected Your unique id is: AE4B724B-B3E8-460E-9BB1-9B1F5186B593
Steps to reproduce the behavior
Running from a freshly reset installation of beta-9:
Kuiper:~ rnixon$ docker run --rm -p 80:80 nginx 172.17.0.1 - - [30/Apr/2016:07:26:48 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36" "-" 172.17.0.1 - - [30/Apr/2016:07:26:48 +0000] "GET /favicon.ico HTTP/1.1" 404 571 "http://localhost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36" "-" 2016/04/30 07:26:48 [error] 6#6: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost", referrer: "http://localhost/" ^CKuiper:~ rnixon$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES Kuiper:~ rnixon$ docker run --rm -p 80:80 nginx docker: Error response from daemon: driver failed programming external connectivity on endpoint modest_einstein (3370d28abe5e44be19af75da2c8ae96d6c977538fb98ccff8ec029b4e3e9a8bb): Error starting userland proxy: Failed to bind: EADDRINUSE.
I can consistently reproduce the EADDRINUSE error provided that I:
- Use the port mapping at least once before removing the container (in the example I’m visiting the Nginx landing page)
- Attempt to run a new container within ~60 seconds of removing the previous container.
It seems as though the port mapping is removed immediately if I do not make any requests over it before removing the container.