I am trying to configure Selenium with Chrome to work with Codeception.
This is my docker-compose.yml file
version: "3.5"
services:
mysql:
image: mysql:8.0
container_name: my-board-mysql
working_dir: /application
command: --default-authentication-plugin=mysql_native_password
hostname: mysql
volumes:
- mysql_storage:/var/lib/mysql
env_file:
- .env
networks:
- backend
ports:
- "9834:3306"
webserver:
build:
dockerfile: ./docker/nginx/Dockerfile
context: .
container_name: my-board-server
working_dir: /application
depends_on:
- php-fpm
networks:
- backend
volumes:
- .:/application
- ./docker/nginx/nginx_local.conf:/etc/nginx/conf.d/default.conf
ports:
- "8924:80"
php-fpm:
build:
dockerfile: docker/php-fpm/Dockerfile-local
context: .
container_name: my-php-fpm
depends_on:
- mysql
volumes:
- .:/application
- ./docker/php-fpm/php-ini-overrides.ini:/etc/php/7.3/fpm/conf.d/99-overrides.ini
networks:
- backend
chrome:
image: selenium/standalone-chrome:latest
ports:
- 4444:4444
container_name: chrome
networks:
- backend
networks:
backend:
driver: bridge
ipam:
config:
- subnet: 172.24.0.0/22
volumes:
mysql_storage:
And this is my Codeception configuration file: acceptance.suite.yml:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://localhost:8924'
browser: chrome
- \App\Tests\Helper\Acceptance
When I navigate to http://localhost:8924 I can see the site, and when I navigate to http://localhost:4444 I can see Selenium page.
When I run Codeception using vendor/bin/codecept run --steps, I can see this failure:
[Facebook\WebDriver\Exception\UnknownErrorException] unknown error: net::ERR_CONNECTION_REFUSED
(Session info: chrome=89.0.4389.82)
It seems that it is not possible to open localhost from webserver which is under docker. Any advice how can I fix this?
I am running this on Mac if it matters.
Related
I have docker-compose.yml file which contains frontend,backend,testing,postgres and pgadmin container. The containers except testing are able to communicate each other. But the testing container fails to communicate with backend and frontend container in docker-compose.
version: '3.7'
services:
frontend:
container_name: test-frontend
build:
context: ./frontend
dockerfile: Dockerfile.local
ports:
- '3000:3000'
networks:
- test-network
environment:
# For the frontend can be applied only during the build!
# (while it's applied when TS is compiled)
# You have to build manually without cache if one of those are changed at least for the prod mode.
- REACT_APP_BACKEND_API=http://localhost:8000/api/v1
- REACT_APP_GOOGLE_CLIENT_ID=1234567dfghjjnfd
- CI=true
- CHOKIDAR_USEPOLLING=true
postgres:
image: postgres
environment:
POSTGRES_USER: dev
POSTGRES_PASSWORD: dev
PGDATA: /data/postgres
volumes:
- postgres:/data/postgres
ports:
- "5432:5432"
networks:
- test-network
restart: unless-stopped
pgadmin:
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: "dev#dev.com"
PGADMIN_DEFAULT_PASSWORD: dev
volumes:
- pgadmin:/root/.pgadmin
- ./pgadmin-config/servers.json:/pgadmin4/servers.json
ports:
- "5050:80"
networks:
- test-network
restart: unless-stopped
backend:
container_name: test-backend
build:
context: ./backend
dockerfile: Dockerfile.local
ports:
- '8000:80'
volumes:
- ./backend:/app
command: >
bash -c "alembic upgrade head
&& exec /start-reload.sh"
networks:
- test-network
depends_on:
- postgres
environment:
- GOOGLE_APPLICATION_CREDENTIALS=/app/.secret/secret.json
- APP_DB_CONNECTION_STRING=postgresql+psycopg2://dev:dev#postgres:5432/postgres
- LOG_LEVEL=debug
- SQLALCHEMY_ECHO=True
- AUTH_ENABLED=True
- CORS=*
- GCP_ALLOWED_DOMAINS=*
testing:
container_name: test-testing
build:
context: ./testing
dockerfile: Dockerfile
volumes:
- ./testing:/isp-app
command: >
bash -c "/wait
&& robot ."
networks:
- test-network
depends_on:
- backend
- frontend
environment:
- WAIT_HOSTS= frontend:3000, backend:8000
- WAIT_TIMEOUT= 3000
- WAIT_SLEEP_INTERVAL=300
- WAIT_HOST_CONNECT_TIMEOUT=300
volumes:
postgres:
pgadmin:
networks:
test-network:
driver: bridge
All the containers are mapped to test-network. When the testing container tried to connect to frontend:3000 or backend:8000, it throws "Host [ backend:8000] not yet available"
How to fix it?
I did follow this tutorial : https://rafrasenberg.com/posts/docker-container-management-with-traefik-v2-and-portainer/ to build a treafik reverse proxy on my server
And I tested it with a very simple application that render a "hello world" in a index.html:
version: "3"
services:
app:
image: nginx
environment:
PORT: ${PORT}
volumes:
- .:/usr/share/nginx/html/
networks:
- proxy
- default
labels:
- "traefik.enable=true"
- "traefik.docker.network=proxy"
- "traefik.http.routers.app-secure.entrypoints=websecure"
- "traefik.http.routers.app-secure.rule=Host(`my-test.localhost`)"
networks:
proxy:
external: true
it works!
Now I want to go on the next step and use it to build a MERN stack project and I'm a bit lost.
usually I dockerize a mern stack by:
create a dockerfile in /server
create a dockerfile in /client
create a docker-compose on the root directory
version: "3.7"
services:
server:
build:
context: ./server
dockerfile: Dockerfile
image: myapp-server
container_name: myapp-node-server
command: /usr/src/app/node_modules/.bin/nodemon server.js
volumes:
- ./server/:/usr/src/app
- /usr/src/app/node_modules
ports:
- 5000
depends_on:
- mongo
env_file: ./server/.env
environment:
- NODE_ENV=development
networks:
- app-network
- proxy
mongo:
image: mongo
volumes:
- data-volume:/data/db
ports:
- 27017
networks:
- app-network
- proxy
client:
build:
context: ./client
dockerfile: Dockerfile
image: myapp-client
container_name: myapp-react-client
command: npm start
volumes:
- ./client/:/usr/app
- /usr/app/node_modules
depends_on:
- server
ports:
- 3001
networks:
- app-network
labels:
- "traefik.enable=true"
- "traefik.docker.network=proxy"
- "traefik.http.routers.app2-secure.entrypoints=websecure"
- "traefik.http.routers.app2-secure.rule=Host(`test.localhost`)"
networks:
app-network:
driver: bridge
proxy:
external: true
volumes:
data-volume:
node_modules:
web-root:
driver: local
But seems that my proxy not working because the console doesn't return any error and it works on localhost:3000 but on test.localhost I have a "Gateway Timeout" error
I created a Symfony environment with Docker. I then included this file in my web project (skeleton website). But when I try to access my base.html.twig page located in a main folder from the controller, I get this error:
Unable to find template "main/base.html.twig" (looked into: /var/www/templates, /var/www/vendor/symfony/twig-bridge/Resources/views/Form).
How can I solve the problem? I have version 5 of Symfony.
Here is the content of my docker-compose file:
version: '3'
services:
php:
container_name: "php-fpm"
build:
context: ./php
environment:
- APP_ENV=${APP_ENV}
- APP_SECRET=${APP_SECRET}
volumes:
- ${APP_FOLDER}:/var/www
networks:
- dev
nginx:
container_name: "nginx"
build:
context: ./nginx
volumes:
- ${APP_FOLDER}:/var/www
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./logs:/var/log/nginx/
depends_on:
- php
ports:
- "80:80"
networks:
- dev
db:
image: mysql
container_name: "db"
restart: always
volumes:
- db-data:/var/lib/mysql
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
networks:
- dev
phpmyadmin:
image: phpmyadmin
container_name: "phpmyadmin"
restart: always
depends_on:
- db
ports:
- 8080:80
environment:
PMA_HOST: db
networks:
- dev
networks:
dev:
volumes:
db-data:
Your Docker Compose file needs to link local folders with Docker folders.
#docker-compose example
version: "3"
services:
web:
build: .
ports:
- "8080:80"
volumes:
- .:/var/www # Map local folder to Docker
ERROR: Encountered errors while bringing up the project.
Docker-compose up -d --build
Docker ps
------------- Docker-compose.yml -----------------
version: "3"
services:
php:
build:
context: ./docker/php
container_name: 'web'
env_file: ./docker/php/.env
restart: 'always'
ports:
- "80:80"
- "443:443"
links:
- mssql
volumes:
- ./:/var/www/html
- ./docker/config/php/php.ini:/usr/local/etc/php/php.ini
- ./docker/config/vhosts:/etc/apache2/sites-enabled
- ./docker/logs/apache2:/var/log/apache2
- ./docker/logs/php:/var/log/php
environment:
PHP_IDE_CONFIG: "serverName=local.dev.com"
mssql:
build: ./docker/mssql
container_name: 'mssql'
env_file: ./docker/mssql/.env
ports:
- "1433:1433"
volumes:
- ./docker/data/mssql:/var/opt/mssql
Make sure your port 80 isn't already in use.
Also, here's a thread with several possible solutions.
This is how my docker-compose.yml file looks like. As you can see, there is a nginx server, a mongoDB, the main application and for testing a nightwatch and selenium container.
nginx:
container_name: 'nginx'
image: 'nginx:1.11'
restart: 'always'
ports:
- '80:80'
- '443:443'
volumes:
- '/opt/nginx/conf.d:/etc/nginx/conf.d:ro'
- '/opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro'
- '/etc/letsencrypt:/etc/letsencrypt'
- '/opt/nginx/www:/var/www:ro'
links:
- 'app'
nightwatch:
container_name: nightwatch
image: 'registry.example.com/project/core:nightwatch'
links:
- selenium
stdin_open: true
tty: true
selenium:
container_name: selenium
image: selenium/standalone-chrome
ports:
- 4444:4444
links:
- app
db:
container_name: db
image: 'mongo:3.4'
restart: 'always'
volumes:
- '/opt/mongo/project/prod:/data/db'
app:
container_name: app
image: 'registry.example.de/project/core:latest'
restart: always
links:
- 'db'
environment:
- ROOT_URL=https://example.com
- MONGO_URL=mongodb://db/db
You can also see, that I'm still using version 1 and I want to upgrade to current version (3). And there are a few problems for converting the file.
For example I do not understand the network option which should be used instead of the deprecated link to get access to containers.
In the nightwatch container I'm running a script like
module.exports = {
'start application': function(browser) {
browser
.url('http://app') // <--
.waitForElementVisible('body', 10000)
.getTitle(function(result) {
this.assert.equal(typeof result, 'string')
})
},
}
So I need to get access to the app container via nightwatch, which also needs selenium. The main app needs of course the db.
I need some help converting to version 3:
version: '3'
services:
nginx:
...
nightwatch:
...
This should be enough:
version: "3"
services:
nginx:
container_name: 'nginx'
image: 'nginx:1.11'
restart: 'always'
ports:
- '80:80'
- '443:443'
volumes:
- '/opt/nginx/conf.d:/etc/nginx/conf.d:ro'
- '/opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro'
- '/etc/letsencrypt:/etc/letsencrypt'
- '/opt/nginx/www:/var/www:ro'
links:
- app
nightwatch:
container_name: nightwatch
image: 'registry.example.com/project/core:nightwatch'
links:
- selenium
stdin_open: true
tty: true
selenium:
container_name: selenium
image: selenium/standalone-chrome
ports:
- 4444:4444
links:
- app
db:
container_name: db
image: 'mongo:3.4'
restart: 'always'
volumes:
- '/opt/mongo/project/prod:/data/db'
app:
container_name: app
image: 'registry.example.de/project/core:latest'
restart: always
links:
- db
environment:
- ROOT_URL=https://example.com
- MONGO_URL=mongodb://db/db
You don't need to configure extra networks than the default provided by compose.
Linking containers is still configured as so. Try this:
version: "3"
services:
abc:
image: ubuntu
command: tail -f /dev/null
cde:
image: busybox
command: ping abc
links:
- abc