I have a docker-compose file with nginx, golang and php services.
When trying to access the php services from golang service, I get an error "Get "http://accounting:9000/": read tcp 172.22.0.5:43016->172.22.0.2:9000: read: connection reset by peer"
I also, want the php service to be accessed only internally, so, it should not be exposed to the outside.
docker-compose.yaml:
version: '3.8'
services:
apigateway:
build:
context: .
dockerfile: .docker/go/apigateway/Dockerfile
depends_on:
- postgres
networks:
- app-network
- internal-network
volumes:
- ./apigateway:/apigateway
accounting:
build:
context: .
dockerfile: .docker/php/Dockerfile
networks:
- internal-network
volumes:
- ./accounting:/var/www/html
depends_on:
- apigateway
nginx:
image: nginx:1.26.0
ports:
- "8780:80"
volumes:
- ./.docker/nginx/conf.d:/etc/nginx/conf.d
depends_on:
- apigateway
networks:
- app-network
- internal-network
networks:
app-network:
internal-network:
internal: true
.docker/php/Dockerfile:
FROM php:8.3-fpm
RUN apt-get update -y
RUN apt-get -y install gcc make autoconf libc-dev pkg-config libzip-dev
WORKDIR /var/www/html
COPY ./accounting .
EXPOSE 9000
CMD ["php-fpm", "-F"]
And here is the code I’m using to test the access from golang:
router.GET("/foo", func(c *gin.Context) {
url := "http://accounting:9000/"
resp, err := http.Get(url)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
fmt.Println(resp.StatusCode)
})
I tried changing the port for php-fpm and I also played with different php -fpm images including alpine but without any success