Cannot get or post data from API with Drupal app served with Docker Compose
You should use \Drupal::httpClient();
instead of curl in drupal 8 (but curl should work too).
What's in your docker-compose.yml ?
Do you have something like this for your services ?
services: api: extra_hosts: - "my_api_hostname.local:0.0.0.0" networks: defaults: aliases: - my_api_hostname.local front: depends_on: - api extra_hosts: - "my_front_hostname.local:0.0.0.0" networks: defaults: aliases: - my_front_hostname.local