docker-compose (macOS) fails with rc4 (Docker Desktop Mac Edge 2.1.5.0). It looks like there's a syntax error or something.
$ docker-compose -f badcompose.yaml up
Creating ddev-d8composer-db ... done
Creating ddev-d8composer-dba ...
Creating ddev-d8composer-web ...
Creating ddev-d8composer-dba ... done
ERROR: for ddev-d8composer-web a bytes-like object is required, not 'str'
ERROR: for web a bytes-like object is required, not 'str'
Traceback (most recent call last):
File "site-packages/docker/api/client.py", line 261, in _raise_for_status
File "site-packages/requests/models.py", line 940, in raise_for_status
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localhost/v1.36/containers/5154c7d2e17e152a31a3513dad4e4354a4a57ba514b83382faff45eec9bb85d1/start
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "compose/service.py", line 625, in start_container
File "compose/container.py", line 241, in start
File "site-packages/docker/utils/decorators.py", line 19, in wrapped
File "site-packages/docker/api/container.py", line 1095, in start
File "site-packages/docker/api/client.py", line 263, in _raise_for_status
File "site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
docker.errors.APIError: 500 Server Error: Internal Server Error ("b'Ports are not available: /forwards/expose/port returned unexpected status: 500'")
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "docker-compose", line 6, in <module>
File "compose/cli/main.py", line 71, in main
File "compose/cli/main.py", line 127, in perform_command
File "compose/cli/main.py", line 1106, in up
File "compose/cli/main.py", line 1102, in up
File "compose/project.py", line 570, in up
File "compose/parallel.py", line 112, in parallel_execute
File "compose/parallel.py", line 210, in producer
File "compose/project.py", line 556, in do
File "compose/service.py", line 546, in execute_convergence_plan
File "compose/service.py", line 467, in _execute_convergence_create
File "compose/parallel.py", line 112, in parallel_execute
File "compose/parallel.py", line 210, in producer
File "compose/service.py", line 465, in <lambda>
File "compose/service.py", line 457, in create_and_start
File "compose/service.py", line 627, in start_container
TypeError: a bytes-like object is required, not 'str'
[87400] Failed to execute script docker-compose
macOS Docker Desktop 2.1.5.0 - on macOS Catalina
Output of docker-compose version
docker-compose version 1.25.0-rc4, build 8f3c9c58
docker-py version: 4.1.0
CPython version: 3.7.4
OpenSSL version: OpenSSL 1.1.1c 28 May 2019
Output of docker version
Client: Docker Engine - Community
Version: 19.03.4
API version: 1.40
Go version: go1.12.10
Git commit: 9013bf5
Built: Thu Oct 17 23:44:48 2019
OS/Arch: darwin/amd64
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 19.03.4
API version: 1.40 (minimum version 1.12)
Go version: go1.12.10
Git commit: 9013bf5
Built: Thu Oct 17 23:50:38 2019
OS/Arch: linux/amd64
Experimental: true
containerd:
Version: v1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
Output of docker-compose config
(Make sure to add the relevant -f
and other flags)
No extra config
docker-compose -f badcompose.yaml up
ERROR: for ddev-d8composer-web a bytes-like object is required, not 'str'
ERROR: for web a bytes-like object is required, not 'str'
Traceback (most recent call last):
File "site-packages/docker/api/client.py", line 261, in _raise_for_status
File "site-packages/requests/models.py", line 940, in raise_for_status
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localhost/v1.36/containers/5154c7d2e17e152a31a3513dad4e4354a4a57ba514b83382faff45eec9bb85d1/start
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "compose/service.py", line 625, in start_container
File "compose/container.py", line 241, in start
File "site-packages/docker/utils/decorators.py", line 19, in wrapped
File "site-packages/docker/api/container.py", line 1095, in start
File "site-packages/docker/api/client.py", line 263, in _raise_for_status
File "site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
docker.errors.APIError: 500 Server Error: Internal Server Error ("b'Ports are not available: /forwards/expose/port returned unexpected status: 500'")
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "docker-compose", line 6, in <module>
File "compose/cli/main.py", line 71, in main
File "compose/cli/main.py", line 127, in perform_command
File "compose/cli/main.py", line 1106, in up
File "compose/cli/main.py", line 1102, in up
File "compose/project.py", line 570, in up
File "compose/parallel.py", line 112, in parallel_execute
File "compose/parallel.py", line 210, in producer
File "compose/project.py", line 556, in do
File "compose/service.py", line 546, in execute_convergence_plan
File "compose/service.py", line 467, in _execute_convergence_create
File "compose/parallel.py", line 112, in parallel_execute
File "compose/parallel.py", line 210, in producer
File "compose/service.py", line 465, in <lambda>
File "compose/service.py", line 457, in create_and_start
File "compose/service.py", line 627, in start_container
TypeError: a bytes-like object is required, not 'str'
[87400] Failed to execute script docker-compose
Here's the contents of badcompose.yaml. This exact style of yaml has been working for at least 2 years with various versions of docker and docker-compose.
networks:
default:
external: true
name: ddev_default
services:
db:
build:
args:
BASE_IMAGE: drud/ddev-dbserver-mariadb-10.2:20191007_many_mariadb
gid: '20'
uid: '501'
username: rfay
context: /Users/rfay/workspace/d8composer/.ddev/.dbimageBuild
command: ''
container_name: ddev-d8composer-db
environment:
COLUMNS: '117'
DDEV_PROJECT: d8composer
LINES: '25'
TZ: ''
healthcheck:
interval: 1s
retries: 30
start_period: 20s
timeout: 2m
hostname: d8composer-db
image: drud/ddev-dbserver-mariadb-10.2:20191007_many_mariadb-built
labels:
com.ddev.app-type: drupal8
com.ddev.approot: /Users/rfay/workspace/d8composer
com.ddev.platform: ddev
com.ddev.site-name: d8composer
ports:
- 127.0.0.1:32768:3306/tcp
restart: "no"
stop_grace_period: 60s
user: '501:20'
volumes:
- source: mariadb-database
target: /var/lib/mysql
type: volume
volume:
nocopy: true
- source: /Users/rfay/workspace/d8composer/.ddev
target: /mnt/ddev_config
type: bind
- ddev-global-cache:/mnt/ddev-global-cache:rw
dba:
container_name: ddev-d8composer-dba
environment:
HTTP_EXPOSE: 8036:8036
PMA_PASSWORD: db
PMA_USER: db
TZ: ''
VIRTUAL_HOST: d8composer.ddev.site,sub1.ddev.site,sub2.ddev.site
healthcheck:
interval: 2m
retries: 1
timeout: 2s
hostname: d8composer-dba
image: drud/phpmyadmin:v1.11.0
labels:
com.ddev.app-type: drupal8
com.ddev.approot: /Users/rfay/workspace/d8composer
com.ddev.platform: ddev
com.ddev.site-name: d8composer
links:
- db:db
ports:
- target: 80
restart: "no"
web:
build:
args:
BASE_IMAGE: drud/ddev-webserver:20191025_mkcert_creation
gid: '20'
uid: '501'
username: rfay
context: /Users/rfay/workspace/d8composer/.ddev/.webimageBuild
cap_add:
- SYS_PTRACE
container_name: ddev-d8composer-web
environment:
COLUMNS: '117'
DDEV_PHP_VERSION: '7.2'
DDEV_PROJECT: d8composer
DDEV_PROJECT_TYPE: drupal8
DDEV_ROUTER_HTTPS_PORT: '443'
DDEV_ROUTER_HTTP_PORT: '80'
DDEV_WEBSERVER_TYPE: nginx-fpm
DDEV_XDEBUG_ENABLED: "false"
DEPLOY_NAME: local
DOCKER_IP: 127.0.0.1
DOCROOT: web
HOST_DOCKER_INTERNAL_IP: ''
HTTPS_EXPOSE: 443:80
HTTP_EXPOSE: 80:80,8025:8025
LINES: '25'
SSH_AUTH_SOCK: /home/.ssh-agent/socket
TZ: ''
VIRTUAL_HOST: d8composer.ddev.site,sub1.ddev.site,sub2.ddev.site
external_links:
- ddev-router:d8composer.ddev.site
- ddev-router:sub1.ddev.site
- ddev-router:sub2.ddev.site
healthcheck:
interval: 1s
retries: 10
start_period: 10s
timeout: 2m
hostname: d8composer-web
image: drud/ddev-webserver:20191025_mkcert_creation-built
labels:
com.ddev.app-type: drupal8
com.ddev.approot: /Users/rfay/workspace/d8composer
com.ddev.platform: ddev
com.ddev.site-name: d8composer
links:
- db:db
ports:
- 127.0.0.1::80/tcp
- 127.0.0.1::443/tcp
restart: "no"
user: '501:20'
volumes:
- source: nfsmount
target: /var/www/html
type: volume
volume:
nocopy: true
- /Users/rfay/workspace/d8composer/.ddev:/mnt/ddev_config:ro
- ddev-global-cache:/mnt/ddev-global-cache:rw
- ddev-ssh-agent_socket_dir:/home/.ssh-agent:rw
version: '3.6'
volumes:
ddev-global-cache:
name: ddev-global-cache
ddev-ssh-agent_socket_dir:
external: true
name: ddev-ssh-agent_socket_dir
mariadb-database:
name: d8composer-mariadb
nfsmount:
driver: local
driver_opts:
device: :/System/Volumes/Data/Users/rfay/workspace/d8composer
o: addr=host.docker.internal,hard,nolock,rw
type: nfs
Hello @rfay
Thank you for opening this report. Could you provide a smaller Compose file triggering this issue? It seems to be related to the port forwarding issue described here: https://github.com/drud/ddev/issues/1888
It could certainly be related to the port-forwarding issue in previous docker 2.1.4.0 issue (https://github.com/docker/for-win/issues/4935), although that one did not manifest in the same way - it did not hit a docker-compose problem.
My bet is that you'll see the problem right away with this docker-compose file; maybe docker is not providing the expected result? I certainly don't doubt that it's docker's fault. Recent edge releases seem to have all had critical issues.
If I were better at python I imagine I could just find "site-packages/docker/api/client.py", line 261, and I'd see what docker is returning that docker-compose doesn't expect.
I finally found a minimal docker-compose.yml
file that causes the same issue:
version: '3.6'
services:
web:
image: nginx
ports:
- 127.0.0.1::80/tcp
- 127.0.0.1::443/tcp
Output:
ERROR: for 6998_web_1 a bytes-like object is required, not 'str'
It also doesn't work with docker-compose
1.24.1 (latest stable release):
ERROR: for d1129e67137b_6998_web_1 Cannot start service web: b'Ports are not available: /forwards/expose/port returned unexpected status: 500'
With only one port
version: '3.6'
services:
web:
image: nginx
ports:
- 127.0.0.1::80/tcp
the container is running but the port forwarding doesn't work because of the unknown source port. We can see it with a docker inspect:
"Ports": {
"80/tcp": [
{
"HostIp": "127.0.0.1",
"HostPort": "32772"
}
]
},
If you set the source port, it just works fine:
version: '3.6'
services:
web:
image: nginx
ports:
- 127.0.0.1:80:80/tcp
- 127.0.0.1:443:443/tcp
And inspect looks good:
"Ports": {
"80/tcp": [
{
"HostIp": "127.0.0.1",
"HostPort": "80"
}
]
},
You can refer to the docker compose documentation about ports to see the different allowed syntaxes: https://docs.docker.com/compose/compose-file/#ports
Nice work. It would be nice to fix docker-compose to handle this (much) more gracefully of course.
I do see the empty published port. That's to get an ephemeral port, and it has always worked in previous docker versions. In the context of this product, we can't just be taking up known localhost ports in advance. (I wonder if it works with the long format if you just leave "published" out)
And BIG THANKS for being so responsive on this.
Ok, so the issue looks like not to be related to random port but with multiple ports exposition.
That's why with the compose file with one random port worked.
It looks like to be related to some changes in Docker Desktop and not in Docker Compose. A ticket has been opened about it. I'll post an update here when I will have more information about it.
@rfay The fix should be released as part of the next Edge release.
https://github.com/docker/for-win/issues/4935
Outstanding, thanks so much @eunomie . Nobody had responded on that issue for 22 days... did it get attended to due to your inquiry? If so, THANKS! And again, thanks for your responsiveness on this.
I hope docker-compose can also be fixed to be more resilient also, even though the underlying flaw is in docker...
facing the problem. Any workaround ?
facing the problem. Any workaround ?
Rollback docker to version 2.1.3.0 and everything is fine, test the latest release of docker this morning the bug was still there :(
Yay, Docker desktop edge 2.1.6.0 resolves this. Thanks so much for your work on this @jcsirot.
I'm using Docker Desktop (Edge) v2.1.6.0 on Mac and also getting this error:
a bytes-like object is required, not 'str'
@gvanto try to provide a super-simple docker-compose file that will demonstrate this with 2.1.6.0. @eunomie did this in https://github.com/docker/compose/issues/6998#issuecomment-549992384 - Does that one give you the error? If not, try to trim yours down to get it.
@rfay the super-simple docker file of @eunomie does not produce this error (un|fortunately). The docker-compose file is rather large, and was working OK until I updated Docker Desktop to this 2.1.6.0 version (from 2.1.4 version I think it was) today
@gvanto Please also try my docker-compose.yaml in the OP, but I think it will work for you.
After that, the best thing is to try to cut yours down piece by piece. Use the "binary search" method, where you delete half of it (by services probably) and see if the problem is still there. Then do it again. Etc.
@rfay the super-simple docker file of @eunomie does not produce this error
If this simple docker file doesn't produce the error, so it's not the same bug.
I suggest you to open a new issue and add all the details from the issue template.
Rolled Docker Desktop back to 2.1.0.5 (stable) and works now ...
Reason for upgrading to Edge was because it has a more recent Kubernetes version (more relevant to k8s documentation out there atm)
Hi,
I'm having this issue on ubuntu 19.04, docker-compose version:
$ sudo docker-compose version
docker-compose version 1.25.0, build 0a186604
docker-py version: 4.1.0
CPython version: 3.7.4
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
docker version:
$ sudo docker version
Client: Docker Engine - Community
Version: 19.03.3
API version: 1.40
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct 8 01:00:44 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.3
API version: 1.40 (minimum version 1.12)
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct 8 00:59:17 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
Going back to docker-compose 1.4.21 fixes the issue for me.
Hi,
I'm having this issue on ubuntu 19.04, docker-compose version:
$ sudo docker-compose version docker-compose version 1.25.0, build 0a186604 docker-py version: 4.1.0 CPython version: 3.7.4 OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
docker version:
$ sudo docker version Client: Docker Engine - Community Version: 19.03.3 API version: 1.40 Go version: go1.12.10 Git commit: a872fc2f86 Built: Tue Oct 8 01:00:44 2019 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.3 API version: 1.40 (minimum version 1.12) Go version: go1.12.10 Git commit: a872fc2f86 Built: Tue Oct 8 00:59:17 2019 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.2.10 GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339 runc: Version: 1.0.0-rc8+dev GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657 docker-init: Version: 0.18.0 GitCommit: fec3683
Going back to docker-compose 1.4.21 fixes the issue for me.
Which version do you mean. Version 1.4.2 doesn't work for me because it says "Unsupported config option for services service: 'db'"
Going back to docker-compose 1.4.21 fixes the issue for me.
Which version do you mean. Version 1.4.2 doesn't work for me because it says "Unsupported config option for services service: 'db'"
I have never said version 1.4.2. Going back from docker-compose 1.25.0 to docker-compose 1.24.1 works for me.
ERROR: for nginx a bytes-like object is required, not 'str'
Traceback (most recent call last):
File "/usr/local/lib/docker/virtualenv/lib/python3.7/site-packages/docker/api/client.py", line 261, in _raise_for_status
response.raise_for_status()
File "/usr/local/lib/docker/virtualenv/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localhost/v1.22/containers/4ad22cdd23306bc704be98bfef2901cbceee964f64374f88cfba5b5671e950c8/start
I have the same error on 2.1.0.5 version :(
Any updates on this? I do not experience this issue, but my coworker does. He is on 2.1.6.0.
2.1.7.0 / compose 1.25.1-rc1 also doesn't work. Unchanged yaml, just upgraded Docker and now nothing works. 😞
Can we get this issue reopened?
Update:
It seems that a broken volume mount causes the same error. In addition to the "bytes-like object" error, I was also getting
docker.errors.APIError: 500 Server Error: Internal Server Error ("b'Mounts denied: \r\nThe path /users/user/project\r\nis not shared from OS X and is not known to Docker.\r\nYou can configure shared paths from Docker -> Preferences... -> File Sharing.\r\nSee https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.\r\n.'")
(even though that directory is configured to be shared; but that's another issue)
If I removed my volumes
from my compose yaml, the "bytes-like object" error also went away.
Weird...
Why is this closed?
I seem to be having the same problem with version 1.25.0
.
docker-compose version:
docker-compose version 1.25.0, build unknown
docker-py version: 4.1.0
CPython version: 3.8.0
OpenSSL version: OpenSSL 1.1.1d 10 Sep 2019
docker version:
Client:
Version: 19.03.5-ce
API version: 1.40
Go version: go1.13.4
Git commit: 633a0ea838
Built: Fri Nov 15 03:19:09 2019
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 19.03.5-ce
API version: 1.40 (minimum version 1.12)
Go version: go1.13.4
Git commit: 633a0ea838
Built: Fri Nov 15 03:17:51 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.3.2.m
GitCommit: d50db0a42053864a270f648048f9a8b4f24eced3.m
runc:
Version: 1.0.0-rc9
GitCommit: d736ef14f0288d6993a1845745d6756cfc9ddd5a
docker-init:
Version: 0.18.0
GitCommit: fec3683
Can confirm this issue as well on version 1.25.0, build b42d419.
I've tried to use the version 1.25.1-rc1
but also does not works.
I'm having the same problem with docker compose version 1.25.0, build 0a186604
➜ docker-compose -v
docker-compose version 1.25.0, build 0a186604
➜ docker -v
Docker version 19.03.5, build 633a0ea838
update:
I removed docker-compose version 1.25.0
reinstalled version 1.16.1
and it works fine.Hope to help.
same
docker-compose -v
docker-compose version 1.25.1-rc1, build d92e9bee
docker -v
Docker version 19.03.5, build 633a0ea
Same here.
docker-compose -v
docker-compose version 1.25.1-rc1, build d92e9bee
docker -v
Docker version 19.03.5, build 633a0ea
Using WSL 2:
wsl --list
Windows Subsystem for Linux Distributions:
Ubuntu-18.04 (Default)
docker-desktop-data
docker-desktop
Is there a known workaround? As it stands I can't use the majority of my containers anymore...
Appear to be having the same issue here.
Stack Trace:
Traceback (most recent call last):
File "site-packages\docker\api\client.py", line 261, in _raise_for_status
File "site-packages\requests\models.py", line 940, in raise_for_status
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localnpipe/v1.38/containers/07da02718216262d9bfa1109b6da73c5bf5a4ad5d1170db34b4d8d1a83fe8490/start
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "compose\service.py", line 625, in start_container
File "compose\container.py", line 241, in start
File "site-packages\docker\utils\decorators.py", line 19, in wrapped
File "site-packages\docker\api\container.py", line 1095, in start
File "site-packages\docker\api\client.py", line 263, in _raise_for_status
File "site-packages\docker\errors.py", line 31, in create_api_error_from_http_exception
docker.errors.APIError: 500 Server Error: Internal Server Error ("b'Ports are not available: listen tcp 0.0.0.0:8545: bind: An attempt was made to access a socket in a way forbidden by its access permissions.'")
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "docker-compose", line 6, in <module>
File "compose\cli\main.py", line 72, in main
File "compose\cli\main.py", line 128, in perform_command
File "compose\cli\main.py", line 1107, in up
File "compose\cli\main.py", line 1103, in up
File "compose\project.py", line 573, in up
File "compose\parallel.py", line 112, in parallel_execute
File "compose\parallel.py", line 210, in producer
File "compose\project.py", line 559, in do
File "compose\service.py", line 546, in execute_convergence_plan
File "compose\service.py", line 467, in _execute_convergence_create
File "compose\parallel.py", line 112, in parallel_execute
File "compose\parallel.py", line 210, in producer
File "compose\service.py", line 465, in <lambda>
File "compose\service.py", line 457, in create_and_start
File "compose\service.py", line 627, in start_container
TypeError: a bytes-like object is required, not 'str'
It appears that the format of errors being thrown on container start has changed, such that the explanation is now bytes rather than str.
create_api_error_from_http_exception
in the docker-py
repo seems to handle it correctly by casting to str - https://github.com/docker/docker-py/blob/4.1.0/docker/errors.py#L24.
In compose it's assuming a string - https://github.com/docker/compose/blob/1.25.1-rc1/compose/service.py#L627
The naive fix seems to be to change ex.explanation
to str(ex.explanation)
.
Just confirmed that making the change outlined above fixed the error, and it now correctly passes through the actual error (("b'Ports are not available: listen tcp 0.0.0.0:8545: bind: An attempt was made to access a socket in a way forbidden by its access permissions.'")
in my case).
Unable to do a PR currently as I'm having other issues on my system, but it's just a simple two-liner changing ex.explanation
references to str(ex.explanation)
in compose.service.start_container
For the posterity:
Actually that's a problem in the error treatment of a string coming from an APIError.explanation, as @keyz182 mentioned in https://github.com/docker/compose/issues/6998#issuecomment-569649664. By this, the error just masks the real problem. This PR should fix the error treatment problem so you can see the real problem. Thank you all for the reportings and even the debugging from @keyz182 !
I found a solution that worked well for me on Ubuntu. I saw this error happened only when I restarted docker service without stopping the running containers first. Then, when I tried to start them again, this error occured. I tried to see if my ports are available and not running in the background (using lsof -i:PORT) but nothing showed. But, if I tried this command using sudo ( sudo lsof -i:PORT ), I noticed that some PID's were running in the background. So I just killed them using ( sudo kill -9 PID ) and docker was working again properly. Just in case someone still gets in trouble, this might help :)
For anyone having the same problem, check if the ports that you are binding from docker-compose are free in the host machine.
same problem,docker-compose version 1.25.0 under ubuntu
@csquan Please try with the latest version of docker-compose
@csquan, please make sure your containers are not trying to use a port that is listening on your host. See below answer from danielts.
I found a solution that worked well for me on Ubuntu. I saw this error happened only when I restarted docker service without stopping the running containers first. Then, when I tried to start them again, this error occured. I tried to see if my ports are available and not running in the background (using lsof -i:PORT) but nothing showed. But, if I tried this command using sudo ( sudo lsof -i:PORT ), I noticed that some PID's were running in the background. So I just killed them using ( sudo kill -9 PID ) and docker was working again properly. _Just in case someone still gets in trouble, this might help :)_
Most helpful comment
For anyone having the same problem, check if the ports that you are binding from docker-compose are free in the host machine.