I need to curl my API from another container.
Container 1 is called nginx
Container 2 is called fpm
I need to by able to bash into my fpm
container and curl the nginx
container.
Config:
#docker-compose.yaml
services:
nginx:
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
volumes:
- ./docker/nginx/conf/dev/api.conf:/etc/nginx/conf.d/default.conf
ports:
- 8080:80
links:
- fpm
fpm:
build:
context: .
dockerfile: ./docker/fpm/Dockerfile
volumes:
- .:/var/www/html
- ./docker/fpm/conf/dev/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
- ./docker/fpm/conf/dev/api.ini:/usr/local/etc/php/conf.d/api.ini
env_file:
- ./docker/mysql/mysql.env
- ./docker/fpm/conf/dev/fpm.env
links:
- mysql
shm_size: 256M
extra_hosts:
- myapi.docker:nginx
My initial thought was to slap it in the extra_hosts
option like:
extra_hosts:
- myapi.docker:nginx
But docker-compose up fails with:
ERROR: for apiwip_fpm_1 Cannot create container for service fpm: invalid IP address in add-host: "nginx"
I have seen some examples of people using docker's network configuration but it seems over the top to just resolve an address.
How can I resolve/eval the IP address of the container rather than just passing it literally?
extra_hosts
parameter is used incorrectly - the values should be in the format<host>:<ip_address>
- see docs.docker.com/compose/compose-file/#extra_hosts . Therefore, thenginx
is taken to be an IP address.