I am trying to set up Codeception to do Acceptance and Functional testing for my web app. Below are my files:
docker-compose.yml
version: '3.7'
services:
# nginx - web server
nginx:
build:
context: ./docker-config/nginx
dockerfile: ./Dockerfile
env_file: &env
- ./cms/.env
init: true
ports:
- "8000:80"
volumes:
- cpresources:/var/www/project/cms/web/cpresources
- ./cms/web:/var/www/project/cms/web:cached
networks:
mmc-network:
aliases:
- mmc.nginx
# php - run php-fpm
php:
build: &php-build
context: ./docker-config/php-prod-craft
dockerfile: ./Dockerfile
depends_on:
- "mysql"
- "redis"
env_file:
*env
expose:
- "9000"
init: true
volumes: &php-volumes
- some volumes............
networks:
mmc-network:
aliases:
- mmc.php
# mysql - database
mysql:
build:
context: ./docker-config/mysql
dockerfile: ./Dockerfile
cap_add:
- SYS_NICE # CAP_SYS_NICE
env_file:
*env
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: project
MYSQL_USER: project
MYSQL_PASSWORD: project
init: true
ports:
- "3306:3306"
volumes:
- db-data:/var/lib/mysql
- ./db-seed/:/docker-entrypoint-initdb.d
networks:
- MMC-network
# redis - key/value database for caching & php sessions
redis:
build:
context: ./docker-config/redis
dockerfile: ./Dockerfile
expose:
- "6379"
init: true
networks:
- mmc-network
# webpack - frontend build system
webpack:
build:
context: ./docker-config/node-dev-webpack
dockerfile: ./Dockerfile
env_file:
*env
init: true
ports:
- "8080:8080"
volumes:
- some volumes..........
networks:
- mmc-network
# selenium - web driver for codeception testing
selenium:
container_name: mmc-selenium
ports:
- "4444:4444"
volumes:
- ./cms:/data
build:
context: ./docker-config/selenium
dockerfile: ./Dockerfile
networks:
mmc-network:
aliases:
- mmc.selenium
volumes:
db-data:
cpresources:
storage:
networks:
mmc-network:
acceptance.suite.dist.yml:
actor: AcceptanceTester
extensions:
enabled:
- Codeception\Extension\RunFailed
- Codeception\Extension\Recorder
modules:
error_level: "E_ALL"
enabled:
- WebDriver:
url: 'http://mmc.nginx'
host: mmc.selenium
port: '4444'
window_size: 1920x1200
browser: 'chrome'
wait: 60
capabilities:
os: Windows
os_version: 10
browserstack.local: true
- \Helper\Acceptance
NavigationCept.php
<?php
$I = new AcceptanceTester($scenario);
# define purpose of the test
$I->wantTo("check that navigation is functional.");
# check all menu items
$I->amOnPage('/');
$I->see('Search');
***Now, point to be noted, Codeception is already installed inside my PHP container and working perfectly.
When I try to run the test, I get the below error which indicates that the connection to my host (which is my Nginx server) has been refused.
I tried with a different url, for example, https://google.com and it just connected fine and everything was successful. Am I doing something wrong in here? Is my url param incorrect? Please help me out if you can. Thanks in advance.
I have seen such exception earlier with Codeception + Selenium. I do not have that project config file to share with you though.
My strong guess here is this error could be due to conflicts around Codeception-ChromeDriver-Selenium versions
Have you tried to execute this on a lower ChromeDriver version say 80 or 75?
Or change the Selenium version?
You could review the following notes which may help you debug this more
https://github.com/Codeception/Codeception/issues/5062
https://stackoverflow.com/a/63760572/2923098
Will update this answer if I find other resources to resolve this.
Docker service are reachable from each other using the service name as hostname. So your configuration could be:
enabled:
- WebDriver:
url: 'http://nginx'
host: selenium
port: '4444'
An alias to a service could be specified at another service as:
selenium:
links:
- "nginx:mmc.nginx"
Then the url could be url: 'http://mmc.nginx'
Workaround: use service IP address
enabled:
- WebDriver:
url: 'http://172.18.0.3'
host: 172.18.0.2
port: '4444'
Test setup using busybox:
docker-compose.yaml that runs 2 dummy web servers with netcat utility for demonstration purposes.
version: '3.7'
services:
nginx:
container_name: mmc-nginx
hostname: mmc-nginx
image: busybox
command: ["sh", "-c", "while true ; do (echo -e 'HTTP/1.1 200 OK\r\nConnection: Close\r\nContent-type: application/xml\r\n\r\n'; echo 'response from '`hostname`':80') | nc -l -p 80 ;done" ]
init: true
ports:
- "8000:80"
networks:
- mmc-network
# selenium - web driver for codeception testing
selenium:
container_name: mmc-selenium
hostname: mmc-selenium
command: ["nc", "-l", "-p", "4444"]
ports:
- "4444:4444"
image: busybox
networks:
- mmc-network
networks:
mmc-network:
name: mmc-network
test command:
docker exec -it mmc-selenium wget -q "http://mmc-nginx" -O -
docker exec -it mmc-selenium wget -q "http://172.18.0.3" -O -
Response:
response from mmc-nginx:80
Access from outside docker network:
wget -q "http://localhost:8000" -O -
response from mmc-nginx:80
Ping to mmc-nginx
docker exec -it mmc-selenium ping -c2 mmc-nginx
PING mmc-nginx (172.18.0.3): 56 data bytes
64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.071 ms
64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.111 ms
--- mmc-nginx ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.071/0.091/0.111 ms
Find service IP address:
Using docker. Change svc value accordingly.:
svc='friendly_solomon' docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$svc"
Using jq. Change svc value accordingly. jq is a great json processing tool to have btw.
svc='mmc-nginx'; docker network inspect bridge | jq -r --arg svc "$svc" '.[] | .Containers | .[] | select(.Name == $svc) | .IPv4Address'
Using grep
svc='mmc-nginx' docker network inspect bridge | grep -A5 "$svc" | grep 'IPv4Address
Related
It seems that when i run Docker compose up, docker is not reading from docker-compose.yml.
It seems like it is loading images from cache or i don't think where is finding them.
Bellow is my docker-compose.yml
version: '3'
services:
httpd:
image: httpd:latest
user: root
ports:
- "80:80" # Default Apache port (Default on PHP 7.4)
- "8073:8073" # PHP 7.3 Apache port
- "8074:8074" # PHP 7.4 Apache port
- "8081:8081" # PHP 8.1 Apache port
volumes:
- ./:/var/www/html/myApp/:rw
- ./dev/Docker/httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf
restart: on-failure
container_name: httpd
networks:
- mb-frontend
php8.1-fpm:
build: ./dev/Docker/php-fpm/8.1
user: root
environment:
XDEBUG_ENABLED: 1
XDEBUG_REMOTE_HOST: host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./:/var/www/html/myApp/:rw
restart: on-failure
container_name: php8.1-fpm
networks:
- mb-frontend
- mb-backend
php7.4-fpm:
build: ./dev/Docker/php-fpm/7.4
user: root
environment:
XDEBUG_ENABLED: 1
XDEBUG_REMOTE_HOST: host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./:/var/www/html/myApp/:rw
restart: on-failure
container_name: php7.4-fpm
networks:
- mb-frontend
- mb-backend
php7.3-fpm:
build: ./dev/Docker/php-fpm/7.3
user: root
environment:
XDEBUG_ENABLED: 1
XDEBUG_REMOTE_HOST: host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./:/var/www/html/myApp/:rw
restart: on-failure
container_name: php7.3-fpm
networks:
- mb-frontend
- mb-backend
db:
image: mariadb:10.3.5
environment:
MYSQL_ROOT_PASSWORD: myPassword
MYSQL_USER: dev
MYSQL_PASSWORD: myPassword
ports:
- "3306:3306"
volumes:
- /root/Bureau/mysql:/var/lib/mysql/:rw
- ./dev/Docker/mariadb/conf.d/:/etc/mysql/conf.d/:rw
- ./dev/Docker/mariadb/config/init.sql:/docker-entrypoint-initdb.d/init.sql
restart: on-failure
container_name: db
networks:
- mb-backend
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: db
volumes:
- /root/Bureau/phpmyadmin:/var/lib/mysql/
networks:
- mb-backend
depends_on:
- db
redis:
image: redis:6.2
container_name: redis
ports:
- "6379:6379"
networks:
- mb-backend
networks:
mb-frontend:
driver: bridge
mb-backend:
driver: bridge
I commented some images on docker-compose.yml but when i tape the command Docker compose up on terminal, all images even commented images are Up.
Can anyone help me how i force docker to read images from the edited docker-compose.yml
Good practice would be do use:
docker compose down
and then
docker compose up
UPDATE:
Next I would suggest to clean up your containers:
List all containers:
docker ps -a
Remove those you don't want because they might still be in the system
docker rm <CONTAINER ID/NAME>
How to Stop & Remove a running container by ID or Name?
The command is actually docker compose up.
The command docker-compose has been deprecated as of latest version. We can now use docker compose without the hyphen(-).
You can use docker-compose -f <path-to-compose-file> to pass in the compose file.
Example:
docker compose -f docker-compose.yml up
Reference documentation: https://docs.docker.com/compose/reference/
We have a project at work that consists of two Laravel apps, one for the backend and one for the frontend. A bit ago we forced https and I have been unable to get the apps to work since then. I've tried to ask for help but I have no experience working with webservers or docker so I had a hard time understanding things and did not want to come across as unintelligent by insisting after I got help. I was instructed to install nginx proxy manager and force https from there. I have also installed portainer and set up the two apps with Laravel sail. I believe at this point I need to somehow set up a host for the front end and force https from NPM on it. Currently, when I try to access the front end I get the3 following error:
papa-frontend | [Wed Nov 24 03:37:43 2021] 172.24.0.1:52864 Accepted
papa-frontend | [Wed Nov 24 03:37:43 2021] 172.24.0.1:52864 Invalid request (Unsupported SSL request)
papa-frontend | [Wed Nov 24 03:37:43 2021] 172.24.0.1:52864 Closing
Here are the two docker-composes I have for sail
The back end
# For more information: https://laravel.com/docs/sail
version: "3"
services:
mci.back:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
image: sail-8.0/app
ports:
- "8001:80"
environment:
LARAVEL_SAIL: 1
volumes:
- ".:/var/www/html"
- "./docker/configs:/etc/supervisor/conf.d"
networks:
- sail
container_name: papa-dashboard
pgsql:
image: postgres:13
ports:
- '${FORWARD_DB_PORT:-5432}:5432'
environment:
PGPASSWORD: '${DB_PASSWORD:-secret}'
POSTGRES_DB: '${DB_DATABASE}'
POSTGRES_USER: '${DB_USERNAME}'
POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
volumes:
- 'sailpgsql:/var/lib/postgresql/data'
networks:
- mci_events_sail
- sail
healthcheck:
test:
[
"CMD",
"pg_isready",
"-q",
"-d",
"${DB_DATABASE}",
"-U",
"${DB_USERNAME}"
]
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- '${FORWARD_MAILHOG_PORT:-1025}:1025'
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
networks:
- sail
networks:
sail:
driver: bridge
mci_events_sail:
external: true
volumes:
sailpgsql:
driver: local
The front end
# For more information: https://laravel.com/docs/sail
version: "3"
services:
mci-front:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
image: sail-8.0/app
ports:
- "8002:80"
environment:
LARAVEL_SAIL: 1
volumes:
- ".:/var/www/html"
networks:
- sail
- mci_events_sail
container_name: papa-frontend
networks:
sail:
driver: bridge
mci_events_sail:
external: true
I created a basic LAPP stack which runs flawlessly on localhost with docker-compose. When I try to make it run with Swarm on production server (1 manager only, no workers), all services go up and get replicated (1/1) but the php-fpm one which keeps restarting with no apparent error.
docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
p0rdrdfmso6x traefik_reverse-proxy replicated 1/1 traefik:v2.4 *:80->80/tcp, *:443->443/tcp
e6vwlo9iw2ny my_stack_apache replicated 1/1 apache:latest *:8000->80/tcp
qy5yigbcjryr my_stack_ftp replicated 1/1 fauria/vsftpd:latest *:20-21->20-21/tcp, *:22100-22110->22100-22110/tcp
n5f9v6bd2854 my_stack_php replicated 0/1 php:latest
rcnbq4vnoz1j my_stack_postgres replicated 1/1 postgres:9.5.24
If we focus on php-fpm container :
docker service ps my_stack_php
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
j6mp3ka40cyo my_stack_php.1 php:latest node.address Ready Ready 2 seconds ago
ezztpsjoglwy \_ my_stack_php.1 php:latest node.address Shutdown Complete 3 seconds ago
gnqjhwpi5y72 \_ my_stack_php.1 php:latest node.address Shutdown Complete 9 seconds ago
0agr3tw0bb9g \_ my_stack_php.1 php:latest node.address Shutdown Complete 15 seconds ago
9a6wsdp4tqqn \_ my_stack_php.1 php:latest node.address Shutdown Complete 21 seconds ago
If I look to the logs :
docker service logs my_stack_php
my_stack_php.1.igd8x7a6ysdi#node.address | Interactive shell
my_stack_php.1.57td5iuk1wwy#node.address | Interactive shell
my_stack_php.1.r03jn931l1uf#node.address | Interactive shell
my_stack_php.1.igd8x7a6ysdi#node.address |
my_stack_php.1.r03jn931l1uf#node.address |
my_stack_php.1.1huf2pdd0bq0#node.address | Interactive shell
my_stack_php.1.57td5iuk1wwy#node.address |
my_stack_php.1.1huf2pdd0bq0#node.address |
It behaves like a container running a command which would end with succes in a few seconds. Swarm launches then an new container to keep the restart contract. However, my php-fpm Dockerfile provide the -F argument that should keep the process running :
PHP Dockerfile
FROM centos:7.4
# ... all installs from Centos to add PHP 7.2 from Remi Collet repositories
RUN mkdir -p /run/php-fpm
RUN usermod -a -G ftp apache
WORKDIR /var/www/html
EXPOSE 9000
# Run in foreground as root (in container POV)
CMD ["php-fpm", "-R", "-F"]
docker-compose.yaml
version: '3.9'
services:
postgres:
image: "postgres:9.5.24"
environment:
POSTGRES_DB: /run/secret/postgres_db
POSTGRES_USER: /run/secret/postgres_user
POSTGRES_PASSWORD: /run/secret/postgres_password
volumes:
- database:/var/lib/postgresql/data
secrets:
- postgres_db
- postgres_user
- postgres_password
deploy:
resources:
limits:
cpus: '0.15'
memory: 128m
networks:
- internal
apache:
env_file: .env
image: apache:latest
build:
context: ./docker/images/apache2.4
dockerfile: prod.Dockerfile
ports:
- 8000:80
environment:
FPM_HOST: php:9000
volumes:
- ./docker/logs/apache/:/var/log/httpd/
networks:
- traefik-public
- internal
deploy:
labels:
- "traefik.enable=true"
- "traefik.http.routers.my_stack.rule=Host(`my-host.com`)"
- "traefik.http.routers.my_stack.entrypoints=websecure"
- "traefik.http.routers.my_stack.tls.certresolver=letsencryptresolver"
- "traefik.http.services.my_stack.loadbalancer.server.port=80"
- "traefik.port=80"
resources:
limits:
cpus: '0.15'
memory: 128m
php:
env_file: .env
image: php:latest
# links:
# - ftp
# - apache
build:
context: ./docker/images/php
dockerfile: prod.Dockerfile
# args:
# TIMEZONE: 'Europe/Paris'
volumes:
- ftp_data:/var/www/ftp:rw
networks:
- internal
deploy:
resources:
limits:
cpus: '0.20'
memory: 512m
ftp:
env_file: .env
image: "fauria/vsftpd:latest"
ports:
- "20:20"
- "21:21"
- "22100-22110:22100-22110"
environment:
FTP_USER: apache
FTP_PASS: /run/secret/automation_client_password
PASV_ADDRESS: 127.0.0.1
PASV_MIN_PORT: 22100
PASV_MAX_PORT: 22110
volumes:
- ftp_data:/home/vsftpd/apache:rw
networks:
- traefik-public
- internal
deploy:
resources:
limits:
cpus: '0.15'
memory: 128m
volumes:
ftp_data:
database:
secrets:
postgres_db:
external: true
postgres_user:
external: true
postgres_password:
external: true
automation_client_password:
external: true
networks:
traefik-public:
external: true
internal:
external: false
Anyone got a clue about this? Any helps/tips will be appreciated.
I don't like this kind of answer, but replica's all went live after complete reboot.
So, I spent about two days and can't make xdebug work in the container (docker-compose config) on the remote server
And I always get E: Time-out connecting to the client. :-(
Dev machine:
Win10 with dynamic IP
All the code is real-time syncing with remote server (via "deployment" feature)
PhpStorm is configured to listen on port 9001, "Listen for PHP Debug Connections" is on.
No servers and etc, just zero-config debugging session.
Remote server:
xdebug config:
xdebug.remote_enable=1
xdebug.remote_port=9001
xdebug.remote_log="/var/www/xdebug.log"
xdebug.remote_connect_back=1
php-fpm, jwilder/nginx-proxy, letsencrypt-companion, nginx, jeroenpeeters/docker-ssh running via docker-compose.
Here is a simplified version of docker-compose.yml:
version: "2"
networks:
default:
external:
name: nginx-proxy
services:
nginx-proxy:
container_name: nginx-proxy
image: jwilder/nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./secured/certs_letsencrypt:/etc/nginx/certs:ro
- /etc/nginx/vhost.d
- /usr/share/nginx/html
restart: always
letsencrypt-companion:
container_name: letsencrypt-companion
image: jrcs/letsencrypt-nginx-proxy-companion
volumes:
- ./secured/certs_letsencrypt:/etc/nginx/certs:rw
- /var/run/docker.sock:/var/run/docker.sock:ro
volumes_from:
- nginx-proxy
restart: always
my_project_nginx:
container_name: my_project_nginx
build:
context: ./containers/nginx_ssl
args:
appcontainer: my_project_app
domain: example.com
depends_on:
- nginx-proxy
links:
- my_project_app
- nginx-proxy
environment:
- VIRTUAL_HOST=example.com
- LETSENCRYPT_HOST=example.com
- LETSENCRYPT_EMAIL=stepan#example.com
restart: always
my_project_app:
container_name: my_project_app
build:
context: .
dockerfile: ./containers/php7_1/Dockerfile
args:
idrsafile: ./secured/id_rsa_shared
php_memory_limit: 6G
depends_on:
- nginx-proxy
restart: always
my_project_ssh:
container_name: my_project_ssh
image: jeroenpeeters/docker-ssh
depends_on:
- my_project_app
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./secured/authorized_keys:/authorized_keys
ports:
- "2227:22"
environment:
- FILTERS={"name":["my_project_app"]}
- AUTH_MECHANISM=publicKey
- AUTHORIZED_KEYS=/authorized_keys
restart: always
The problem
And there is xdebug log:
...
I: Checking remote connect back address.
I: Remote address found, connecting to 5.18.238.83:9001.
E: Time-out connecting to the client. :-(
I tried a lot of variants (specified xdebug.remote_host, established SSH tunnel via Putty etc) and still got no results.
I set up 2 projects (Admin and API) and try to move into docker on local.
I can access the running web instances on both without any problems, but when the Admin tries to make a Curl requests to the API, I get a cURL error:
cURL error 7: Failed to connect to localhost port 8080
This is my docker-compose.yml file contents:
version: "3.1"
services:
memcached:
image: memcached:alpine
container_name: project-admin-memcached
redis:
image: redis:alpine
container_name: project-admin-redis
mariadb:
image: mariadb:10.1
container_name: project-admin-mariadb
working_dir: /application
volumes:
- ./Projects:/application
environment:
- MYSQL_ROOT_PASSWORD=docker
- MYSQL_DATABASE=db_test
- MYSQL_USER=test
- MYSQL_PASSWORD=test
ports:
- "8083:3306"
# docker-compose exec webserver sh
# docker exec -it project-admin-webserver nginx -s reload
webserver:
image: nginx:alpine
container_name: project-admin-webserver
working_dir: /application
volumes:
- ./Projects/Api:/application/api
- ./Projects/Admin:/application/admin
- ./Docker/nginx:/etc/nginx/conf.d
ports:
- "8080:8080"
- "8090:8090"
# docker-compose exec php-fpm bash
php-fpm:
build: Docker/php-fpm
container_name: project-admin-php-fpm
working_dir: /application
volumes:
- ./Projects:/application
- ./Docker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
I can access both projects from my browser with:
http://localhost:8080/ <= API
http://localhost:8090/ <= Admin
How can I fix this?
inside your docker network (create by default with a compose), you have to use the container name.
So inside a container you have to use http://webserver:8080