Accessing main app container from service container via hostname
Summary
Main container app should have his own hostname injected into /etc/hosts of service containers.
Steps to reproduce
Got 2 containers. One with main app and service container with selenium webdriver. Selenium container should connect to main app for testing purposes.
It is using name of container like in https://docs.gitlab.com/ce/ci/docker/using_docker_images.html#accessing-the-services
But cannot connect.
Actual behavior
Gitlab CI files
image: fones/ruby-node:2.3.1-6.9.5
... # not importatnt
rspec-integration:
stage: test
services:
- mysql:latest
- selenium/standalone-firefox:latest
variables:
RAILS_ENV: "test"
MYSQL_DATABASE: "test"
MYSQL_ROOT_PASSWORD: "toor"
TEST_DATABASE_URL: "mysql2://root:toor@mysql:3306/test"
TEST_DB_POOL: "5"
SELENIUM_URL: "http://selenium__standalone-firefox:4444"
CAPYBARA_APP_HOST: "http://fones__ruby-node:8080"
CAPYBARA_SERVER_HOST: "fones__ruby-node"
CAPYBARA_SERVER_PORT: "8080"
CAPYBARA_JAVASCRIPT_DRIVER_DOCKER: "1"
script:
- bundle install --path vendor/bundle
- bin/rails db:schema:load
- npm install
- npm install -g bower
- bower install --allow-root
- rspec spec/integration/
cache:
paths:
- vendor/bundle/
- vendor/assets/bower_components/
- node_modules/
Selenium config:
# Capybara settings
Capybara.app_host = ENV['CAPYBARA_APP_HOST'] || 'http://localhost:8080'
Capybara.run_server = true # Whether start server when testing
Capybara.server_host = ENV['CAPYBARA_SERVER_HOST'] || "localhost"
Capybara.server_port = ENV['CAPYBARA_SERVER_PORT'] || 8080
Capybara.default_selector = :css
Capybara.ignore_hidden_elements = true
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(
app,
browser: :firefox,
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.firefox(marionette: false)
)
end
Capybara.register_driver :selenium_docker do |app|
Capybara::Selenium::Driver.new(
app,
browser: :remote,
url: "#{ENV['SELENIUM_URL']}/wd/hub",
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.firefox
)
end
Capybara.javascript_driver = ENV['CAPYBARA_JAVASCRIPT_DRIVER_DOCKER'] ? :selenium_docker : :selenium
Selenium is trying to connect
http://fones__ruby-node:8080
Got error
SocketError:
Failed to open TCP connection to fones__ruby-node:8080 (getaddrinfo: Name or service not known)
# ./spec/integration/landing_spec.rb:6:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# SocketError:
# getaddrinfo: Name or service not known
# ./spec/integration/landing_spec.rb:6:in `block (2 levels) in <top (required)>'
Expected behavior
It should have way to connect main app.
Environment description
Using my own runner with docker executor on Gitlab.com
Docker info
Containers: 6
Running: 2
Paused: 0
Stopped: 4
Images: 8
Server Version: 1.13.0
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 83
Dirperm1 Supported: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 03e5862ec0d8d3b3f750e19fca3ee367e13c090e
runc version: 2f7393a47307a16f8cee44a37b262e8b81021e3e
init version: 949e6fa
Security Options:
apparmor
Kernel Version: 3.13.0-24-generic
Operating System: Ubuntu 14.04.5 LTS
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 7.759 GiB
Name: srv
ID: CEWL:6C35:NN2R:TRGG:S6DH:B4QM:TBOY:55FJ:UGQZ:EYVR:5EA3:HSQS
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
WARNING: No kernel memory limit support
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Gemfile:
gem 'selenium-webdriver', '~> 3.0'
Used GitLab Runner version
Version: 1.10.3
Git revision: ba2bc36
Git branch: 1-10-stable
GO version: go1.7.4
Built: Fri, 27 Jan 2017 14:49:03 +0000
OS/Arch: linux/amd64