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/
Related
I'm running one container nginx_cont for frontend and one container web_cont for backend.
I would like my nginx in my frontend container to reach my backend container by its name with
proxy_pass http://web_cont:8000;
I've tried with the container ip and it is working. I 've tried with the name web_cont_1 as my docker-compose is adding number. And i've tried with web_cont_1.spa_network as I have specified networks: spa_network: in my docker-compose.yml.
I get the error :
nginx_cont_1 | 2022/06/01 12:00:23 [emerg] 1#1: host not found in upstream "web_cont_1" in /etc/nginx/conf.d/nginx.conf:12
Note that when i do docker-compose run containername commande, i get the error
ERROR: No such service: containername
containername is the name i get when i run docker-compose ps
Any hints?
this is my docker-compose.yml
version: '3.7'
services:
nginx_cont:
build:
context: .
dockerfile: ./compose/production/nginx/Dockerfile
restart: always
volumes:
- staticfiles:/app/static
- mediafiles:/app/media
ports:
- 80:80
- 3000:3000
- 6006:6006
depends_on:
- web_cont
networks:
spa_network:
web_cont:
build:
context: .
dockerfile: ./compose/production/django/Dockerfile
restart: always
command: /start
volumes:
- staticfiles:/app/static
- mediafiles:/app/media
- sqlite_db:/app/db
ports:
- 8000:8000
env_file:
- ./env/prod-sample
networks:
spa_network:
ipv4_address: 172.20.128.2
networks:
spa_network:
ipam:
config:
- subnet: 172.20.0.0/16
volumes:
sqlite_db:
staticfiles:
mediafiles:
Thank you
I'm using docker-compose for terramoney.
Here is docker-compose.yml file.
version: "3"
services:
terrad:
image: terramoney/localterra-core:0.5.18
volumes:
- ./config:/root/.terra/config
networks:
- terra
ports:
- "26657:26657"
- "1317:1317"
- "9090:9090"
- "9091:9091"
command: terrad start
oracle:
image: terramoney/pseudo-feeder:0.5.6
depends_on:
- terrad
volumes:
- ./config/config.toml:/app/config.toml
networks:
- terra
environment:
TESTNET_LCD_URL: http://terrad:1317
command: start
postgres:
image: postgres:12
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
networks:
- terra
environment:
POSTGRES_USER: dev
POSTGRES_PASSWORD: dev
# redis:
# image: redis:latest
# networks:
# - terra
# ports:
# - "6379:6379"
fcd-collector:
image: terramoney/fcd:1.0.14
depends_on:
- terrad
- postgres
volumes:
- ./logs:/app/logs
networks:
- terra
env_file: fcd.env
command: collector
restart: unless-stopped
fcd-api:
image: terramoney/fcd:1.0.14
depends_on:
- terrad
- postgres
volumes:
- ./logs:/app/logs
networks:
- terra
ports:
- 3060:3060
env_file: fcd.env
command: start
networks:
terra:
driver: bridge
When I run sudo docker-compose up, I got this error.
Starting localterra_terrad_1 ... Starting localterra_postgres_1 ...
error
ERROR: for localterra_postgres_1 Cannot start service postgres: OCI
runtime creStarting localterra_terrad_1 ... error
2d5e1c2ce6c114821010c6: unknown
ERROR: for localterra_terrad_1 Cannot start service terrad: OCI
runtime create failed: container with id exists:
0d03712d982f9b6f1d67c36735f4aefddb874e65958965e1bca54a782f525c6e:
unknown
ERROR: for postgres Cannot start service postgres: OCI runtime create
failed: container with id exists:
ea889e63356e0d77d5196b2c73d1696089944fcbab2d5e1c2ce6c114821010c6:
unknown
ERROR: for terrad Cannot start service terrad: OCI runtime create
failed: container with id exists:
0d03712d982f9b6f1d67c36735f4aefddb874e65958965e1bca54a782f525c6e:
unknown ERROR: Encountered errors while bringing up the project.
If anyone familiar with docker and terramoney, please help me.
I may have installed docker incorrectly.
After install docker, my docker desktop is stopped.
This is root directory
├─── config/
├─── img/
├─── pseudo-feeder/
└─── terracore/
docker-compose.yml
fcd.env
init.sql
LICENSE
README.md
I've created docker-compose.yml file with the following content. My docker service runs ok, docker run hello-world works just fine and after running command
docker-compose build && docker-compose up -d
I see no errors but in the browser I'm getting an error Unable to connect when I go to localhost:8000
version: '3'
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- "8000:80"
depends_on:
- php
- mysql
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
mysql:
image: mysql:8.0
container_name: mysql
restart: unless-stopped
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: db
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: root
SERVICE_NAME: mysql
When I run command
docker-compose exec php ls
I can see the list of files and folders
i keep getting this error for my docker build :
"0":"SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not
known","1":"#1 Zend_Db_Adapter_Pdo_Mysql->_connect()
However, if i docker-compose down and then docker-compose up it works for a coupe of mins and then crashes again.
Is this to do with the network cache. Is there somthing that i should clear ?
this is my docker compose file. --you will note that i do provide a link to database:
version: "2"
services:
web:
build: ./developer
ports:
- "8228:80"
links:
- database
volumes:
- total-sync:/var/www/html:nocopy
env_file:
- env
database:
image: mysql:5.7
ports:
- "3907:3316"
command: --default-authentication-plugin=mysql_native_password
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=default
volumes:
- ./dump:/docker-entrypoint-initdb.d
- ./db/mysqlconf:/etc/mysql/conf.d
- ./mysqladata2.3.4:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- "8583:80"
links:
- database
volumes:
total-sync:
external: true
dbdatas:
driver: local
Below is my docker-compose.yml which composing two docker files :
mysql.dockerfile
FROM mysql:8
ADD DockerImages/mysql /docker-entrypoint-initdb.d/
springapp.dockerfile
FROM maven:3.5-jdk-8 <br>
ADD target/users-mysql.jar users-mysql.jar<br>
ENTRYPOINT ["/usr/bin/java"]<br>
CMD ["-jar", "users-mysql.jar"]<br>
VOLUME /var/lib/spring-cloud/config-repo
docker-compose.yml
version: '3'
services:
springapp:
build:
context: .
dockerfile: springapp.dockerfile
expose:
- "8888"
ports:
- 8888:8888
links:
- mysqldb:mysqldb
networks:
- spring-demo-network
depends_on:
- mysqldb
environment:
- DATABASE_HOST=mysqldb
- DATABASE_USER=gl_user
- DATABASE_PASSWORD=global#123
- DATABASE_NAME=test_db
mysqldb:
build:
context: .
dockerfile: mysql.dockerfile
ports:
- 3306:3306
container_name : mysql-standalone
networks:
- spring-demo-network
environment:
MYSQL_DATABASE: test_db
MYSQL_USER: gl_user
MYSQL_PASSWORD: global#123
MYSQL_ROOT_PASSWORD: root
MYSQL_ROOT_HOST: '%'
networks:
spring-demo-network:
driver: bridge
I am unable to connect to the database its throws multiple errors like
Error:
java.sql.SQLException: null, message from server: "Host '172.18.0.3'
is not allowed to connect to this MySQL server"
Caused by: java.net.ConnectException: Connection refused (Connection
refused)