I have an issue I discovered while trying to try PHPUnit tests with CURL commands. I always get:
Connecting to `www.example.local` (www.example.local)|127.0.0.1|:80... failed: Connection refused.
I then tried to run wget and curl commands from the container command line, same problem. I have docker working like this.
In my computer’s /etc/hosts
127.0.0.1 www.example.local
127.0.0.1 api.example.local
and so forth and it works when accessing the sites in my browser. In my docker-compse.yml, I have:
version: “3.4”
volumes:
postgres_database :
external: false
mysql_data : {}
schemas:
external: false
services:
php:
build:
context : ./
dockerfile : Dockerfile
network: host
volumes:
- ./:/code
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
depends_on: [ "postgres"]
ports:
- "9000:9000"
expose:
- "9000"
container_name: binge_php
web:
image: nginx:latest
build:
context : ./
dockerfile : Dockerfile_Nginx
network: host
ports:
- "80:80"
expose:
- "0"
volumes:
- ./:/code
- ./site.conf:/etc/nginx/conf.d/site.conf
- ./nginx_custom_settings.conf:/etc/nginx/conf.d/nginx_custom_settings.conf
links:
- php
depends_on:
- php
container_name: binge_nginx
What might I be doing wrong that is preventing me from running curl commands from inside the PHP container?
Related
I am beginner in Docker and can not get response from my project that running in docker. I have a Go project with 4 services. When It Run as local machine in my pc, everything is good and not have problem. But when it run in docker and send request by postman, could not get response and socket hang up was present.
I have 4 service for this:
1- Rest API service that dockerfile is :
FROM golang:latest as GolangBase
...
...
EXPOSE 8082
CMD ["/go/bin/ecg", "server"]
2- Page service that dockerfile is :
FROM golang:latest as GolangBase
...
...
EXPOSE 8080
CMD ["/go/bin/ecg", "page"]
2- Redis
3- Postgres
docker-compose in root:
version: "2.3"
services:
server:
build:
context: .
dockerfile: docker/app/Dockerfile
container_name: ecg-go
ports:
- "127.0.0.1:8082:8082"
depends_on:
- postgres
- redis
networks:
- ecg-service_default
restart: always
page:
build:
context: .
dockerfile: docker/page/Dockerfile
container_name: ecg-page
ports:
- "127.0.0.1:8080:8080"
depends_on:
- postgres
networks:
- ecg-service_default
restart: always
redis:
image: redis:6
container_name: ecg-redis
volumes:
- redis_data:/data
networks:
- ecg-service_default
postgres:
image: postgres:alpine
container_name: ecg-postgres
environment:
POSTGRES_PASSWORD: docker
POSTGRES_DB: ecg
POSTGRES_USER: ecg
volumes:
- pg_data:/var/lib/postgresql/data
networks:
- ecg-service_default
volumes:
pg_data:
redis_data:
networks:
ecg-service_default:
I build images and run containers by docker-compose up -d command and all services is created and running.
But when sending Request to http://localhost:8082/.. it return Could not get response, socket hang up.
What's the problem ??
I configured PhpStorm for running tests from docker container in the IDE by clicking the Run button, but I got the following error when I run them:
Doctrine\DBAL\Exception\ConnectionException : An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
from .env:
database_host: sp_mysql
database_port: null
docker-compose:
version: "3.4"
services:
nginx:
container_name: sp_nginx
image: nginx
ports:
- 8080:80
volumes:
- ./docker/nginx/conf:/etc/nginx/conf.d/:ro
- ./var/log/nginx/:/var/log/nginx:cached
- ./web:/app/web
depends_on:
- php
networks:
- internal
php:
container_name: sp_php
image: sp/php
build:
context: ./
dockerfile: ./docker/php/Dockerfile
volumes:
- ./:/app
- ~/.ssh:/root/.ssh
depends_on:
- mysql
networks:
- internal
mysql:
container_name: sp_mysql
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
volumes:
- ./docker/mysql/conf:/etc/mysql/conf.d
- mysql_data:/var/lib/mysql
ports:
- 3308:3306
networks:
- internal
networks:
internal:
volumes:
mysql_data:
But if I go directly to php container it works:
docker exec -it sp_php vendor/bin/phpunit
i setup my ide Docker/PHPUnit config by this guide:
https://www.youtube.com/watch?v=I7aGWO6K3Ho&t=240s
To solve this problem i set this in .env
host: "172.19.0.1" // docker network bridge gateway
port: "3308" // my db port from docker-compose
https://docs.docker.com/network/network-tutorial-standalone/
I'm working as a DevOps for some of the Projects Where I am facing an issue,
I have one docker-compose.yml which is working fine with local IP like 192.168.0.38 but I want to map it with my AWS IP (54.xxx.xxx.23) instead of local host IP.
version: '3'
services:
api:
build: ./api
image: api
environment:
- PYTHONUNBUFFERED=1
expose:
- ${scikiqapiport}
ports:
- ${scikiqapiport}:${scikiqapiport}
command:
"python3 manage.py makemigrations"
command:
"chmod -R 777 ./scikiq/scikiq/static:rw"
command:
"python3 manage.py migrate"
command: "gunicorn --workers=3 --bind=0.0.0.0:${scikiqapiport} wsgi"
restart: on-failure
depends_on:
- base
volumes:
- "../compressfile:/home/data/arun/compressfile"
- "static:/home/data/arun/scikiq/scikiq/static:rw"
scikiqweb:
build: ./web
image: web
ports:
- ${scikiqwebport}
command:
"gunicorn --workers=3 --bind=0.0.0.0:${scikiqwebport} wsgi"
restart: on-failure
depends_on:
- base
nginx:
image: nginx
ports:
- ${scikiqwebport}:80
volumes:
- ./nginx:/etc/nginx/conf.d
depends_on:
- scikiqweb1
base:
build: ./base-image
image: scikiq_base
volumes:
compressfile:
static:
Your help will be appreciated.
Thank You
Put the public IP where is used local IP its working
I want use Docker run my project(react+nodejs+mongodb),
Dockerfile:
FROM node:8.9-alpine
ENV NODE_ENV production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm install --production --silent && mv node_modules ../
COPY . .
CMD nohup sh -c 'npm start && node ./server/server.js'
docker-compose.yml:
version: '2.1'
services:
chat:
image: chat
container_name: chat
build: .
environment:
NODE_ENV: production
ports:
- "3000:3000"
- "8080:8080"
volumes:
- ./:/usr/src/app
links:
- mongo
mongo:
container_name: mongo
image: mongo
ports:
- "27017:27017"
run docker-compose up --build, the 3000 port is worked, but the 8080 port dies
localhost:3000
localhost:8080
I would suggest create a container for the server and have it seperate from the "chat" container. Its best to have each container do one thing and one thing only (almost like the philosophy behind unix commands)
In any case here is some modifications that I would make to the compose file.
version: '2.1'
services:
chat:
image: chat
container_name: chat
build: .
environment:
NODE_ENV: production
ports:
- "3000:3000"
- "8080:8080"
volumes:
- ./:/usr/src/app
links:
- mongo
mongo:
container_name: mongo
image: mongo
# You don't need to expose this port to the outside world. Because you linked the two containers the chat app
# will be able to connect to mongodb using hostname mongodb inside the container network.
# ports:
# - "27017:27017"
Btw what happens if you run:
$ docker-compose down
and then
$ docker-compose up
$ docker ps
can you see the ports exposed in docker ps output?
your chat service depends on mongo so you also need to have this in your chat
depends_on:
- mongo
This docker-compose file works for me. Note that i am saving the data from the database to a local directory. You should add this directory to gitignore.
version: "3.2"
services:
mongo:
container_name: mongo
image: mongo:latest
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=password
- NODE_ENV=production
ports:
- "28017:27017"
expose:
- 28017 # you can connect to this mongodb with studio3t
volumes:
- ./mongodb-data:/data/db
restart: always
networks:
- docker-network
express:
container_name: express
environment:
- NODE_ENV=development
restart: always
build:
context: .
args:
buildno: 1
expose:
- 3000
ports:
- "3000:3000"
links:
- mongo # link this service to the database service
depends_on:
- mongo
command: "npm start" # override the default command to use nodemon in dev
networks:
- docker-network
networks:
docker-network:
driver: bridge
You may also find that using node you have to wait for the mongodb container to be ready before you can connect to the database.
I'm trying to run a web app within a docker container. This is my docker-compose.yml
version: '2'
services:
web-app:
image: org/webapp
container_name: web-app
ports:
- "8080:8080"
expose:
- "8080"
volumes:
- ./code/source:/source
command: tail -f /dev/null
postgres:
image: postgres:9.5
container_name: local-postgres9.5
volumes_from:
- postgres-data
postgres-data:
image: busybox
container_name: postgres9.5-data
volumes:
- /var/lib/postgresql/data
When I run
docker-compose up -d
I'm able to connect to the web app from within the container with a curl command. When I try to connect from the host, I get a connection refused error