Как достучаться из одного контейнера в другой в CircleCI?
Есть такая штука как CircleCI. В доках приведён пример запуска сразу двух контейнеров:
rake_test:
docker:
- image: circleci/ruby:2.4-node-jessie
- image: circleci/postgres:9.4.12-alpine
steps:
...
- run: bundle --path vendor/bundle
Как виртуалка с ruby знает, что рядом есть pg и что надо стучаться именно туда? Коллега кинул ссылку на ман по Docker Compose, но я там тоже не понял механизм именно сетевого взаимодействия.
P.S. Про докер только читал и знаю в общих чертах. В продакшене не работал.
P.P.S. Этот ответ видел, но всё равно не понятно как применять в конкретно моём случае.
Ответы (1 шт):
Всё оказалось просто и на поверхности. Оказывается у CircleCI есть первичный контейнер в котором выполняются все bash\python\php\js\etc скрипты и есть остальные котейнеры, которые доступны по сети в виде localhost:port из первичного контейнера. Всё написано тут.
Как пример - я решил попробовать связку ubuntu 18.04 и nginx.
.circleci/config.yml:
---
version: 2.1
executors:
test-bridge:
resource_class: small
docker:
- image: ubuntu:18.04
- image: nginx:latest
jobs:
run-test-bridge:
executor: test-bridge
steps:
- checkout
- run:
name: Run 2 containers 4 test local network
command: |
cat /etc/os-release
apt update
apt -y install wget
wget -O - http://localhost/
workflows:
simple-run-test:
jobs:
- run-test-bridge
Выхлоп получился такой:
NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
0% [Working]
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
0% [Connecting to archive.ubuntu.com (91.189.88.142)] [1 InRelease 2586 B/88.7
0% [Connecting to archive.ubuntu.com (91.189.88.142)]
0% [1 InRelease gpgv 88.7 kB] [Waiting for headers]
Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]
0% [1 InRelease gpgv 88.7 kB] [2 InRelease 14.2 kB/242 kB 6%]
0% [2 InRelease 14.2 kB/242 kB 6%]
Get:3 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [854 kB]
0% [2 InRelease 28.7 kB/242 kB 12%] [3 Packages 11.4 kB/854 kB 1%]
0% [2 InRelease 43.1 kB/242 kB 18%]
0% [3 Packages store 0 B] [2 InRelease 43.1 kB/242 kB 18%] [Waiting for headers
Get:4 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [8815 B]
0% [3 Packages store 0 B] [2 InRelease 43.1 kB/242 kB 18%] [4 Packages 8815 B/8
0% [3 Packages store 0 B] [2 InRelease 43.1 kB/242 kB 18%]
Get:5 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [59.3 kB]
0% [3 Packages store 0 B] [2 InRelease 43.1 kB/242 kB 18%] [5 Packages 30.5 kB/
0% [3 Packages store 0 B] [2 InRelease 43.1 kB/242 kB 18%] [Waiting for headers
Get:6 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [931 kB]
0% [3 Packages store 0 B] [2 InRelease 43.1 kB/242 kB 18%] [6 Packages 36.5 kB/
0% [3 Packages store 0 B] [2 InRelease 48.9 kB/242 kB 20%]
0% [2 InRelease 92.4 kB/242 kB 38%]
0% [4 Packages store 0 B] [2 InRelease 92.4 kB/242 kB 38%]
0% [2 InRelease 92.4 kB/242 kB 38%]
0% [5 Packages store 0 B] [2 InRelease 92.4 kB/242 kB 38%]
0% [2 InRelease 101 kB/242 kB 42%]
0% [6 Packages store 0 B] [2 InRelease 101 kB/242 kB 42%]
0% [2 InRelease 205 kB/242 kB 85%]
0% [Working]
0% [2 InRelease gpgv 242 kB] [Waiting for headers]
Get:7 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
0% [2 InRelease gpgv 242 kB] [7 InRelease 2604 B/88.7 kB 3%]
0% [2 InRelease gpgv 242 kB]
0% [Waiting for headers]
0% [7 InRelease gpgv 88.7 kB] [Waiting for headers]
Get:8 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
0% [7 InRelease gpgv 88.7 kB] [8 InRelease 2604 B/74.6 kB 3%]
0% [7 InRelease gpgv 88.7 kB]
0% [Waiting for headers]
0% [8 InRelease gpgv 74.6 kB] [Waiting for headers]
Get:9 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages [1344 kB]
0% [8 InRelease gpgv 74.6 kB] [9 Packages 2685 B/1344 kB 0%]
26% [9 Packages 213 kB/1344 kB 16%]
31% [Waiting for headers]
Get:10 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [11.3 MB]
31% [10 Packages 3749 B/11.3 MB 0%]
31% [9 Packages store 0 B] [10 Packages 3749 B/11.3 MB 0%]
41% [10 Packages 2251 kB/11.3 MB 20%]
82% [Working]
Get:11 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [186 kB]
82% [11 Packages 16.0 kB/186 kB 9%]
82% [10 Packages store 0 B] [11 Packages 16.0 kB/186 kB 9%]
83% [10 Packages store 0 B] [Waiting for headers]
Get:12 http://archive.ubuntu.com/ubuntu bionic/restricted amd64 Packages [13.5 kB]
83% [10 Packages store 0 B] [12 Packages 13.5 kB/13.5 kB 100%]
83% [10 Packages store 0 B]
Get:13 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [20.1 kB]
83% [10 Packages store 0 B] [13 Packages 12.7 kB/20.1 kB 63%]
83% [10 Packages store 0 B]
Get:14 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1385 kB]
83% [10 Packages store 0 B] [14 Packages 29.8 kB/1385 kB 2%]
89% [10 Packages store 0 B] [Waiting for headers]
Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [73.6 kB]
89% [10 Packages store 0 B] [15 Packages 21.7 kB/73.6 kB 29%]
89% [10 Packages store 0 B] [Waiting for headers]
Get:16 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [1228 kB]
90% [10 Packages store 0 B] [16 Packages 20.2 kB/1228 kB 2%]
95% [10 Packages store 0 B] [Waiting for headers]
Get:17 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [8158 B]
95% [10 Packages store 0 B] [17 Packages 8158 B/8158 B 100%]
95% [10 Packages store 0 B]
Get:18 http://archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [8286 B]
95% [10 Packages store 0 B] [18 Packages 8286 B/8286 B 100%]
95% [10 Packages store 0 B]
95% [10 Packages store 0 B]
96% [Working]
96% [11 Packages store 0 B]
96% [Working]
96% [12 Packages store 0 B]
97% [Working]
97% [13 Packages store 0 B]
97% [Working]
97% [14 Packages store 0 B]
98% [Working]
98% [15 Packages store 0 B]
98% [Working]
98% [16 Packages store 0 B]
99% [Working]
99% [17 Packages store 0 B]
99% [Working]
99% [18 Packages store 0 B]
100% [Working]
Fetched 18.0 MB in 3s (6556 kB/s)
Reading package lists... 0%
Reading package lists... 0%
Reading package lists... 0%
Reading package lists... 7%
Reading package lists... 7%
Reading package lists... 7%
Reading package lists... 7%
Reading package lists... 61%
Reading package lists... 67%
Reading package lists... 67%
Reading package lists... 68%
Reading package lists... 68%
Reading package lists... 76%
Reading package lists... 76%
Reading package lists... 77%
Reading package lists... 77%
Reading package lists... 86%
Reading package lists... 86%
Reading package lists... 87%
Reading package lists... 87%
Reading package lists... 87%
Reading package lists... 87%
Reading package lists... 87%
Reading package lists... 87%
Reading package lists... 93%
Reading package lists... 93%
Reading package lists... 93%
Reading package lists... 93%
Reading package lists... 99%
Reading package lists... 99%
Reading package lists... 99%
Reading package lists... 99%
Reading package lists... Done
Building dependency tree... 0%
Building dependency tree... 0%
Building dependency tree... 0%
Building dependency tree... 50%
Building dependency tree... 50%
Building dependency tree
Reading state information... 0%
Reading state information... 0%
Reading state information... Done
4 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... 0%
Reading package lists... 0%
Reading package lists... 0%
Reading package lists... 7%
Reading package lists... 7%
Reading package lists... 7%
Reading package lists... 7%
Reading package lists... 63%
Reading package lists... 67%
Reading package lists... 67%
Reading package lists... 68%
Reading package lists... 68%
Reading package lists... 76%
Reading package lists... 76%
Reading package lists... 77%
Reading package lists... 77%
Reading package lists... 86%
Reading package lists... 86%
Reading package lists... 87%
Reading package lists... 87%
Reading package lists... 87%
Reading package lists... 87%
Reading package lists... 87%
Reading package lists... 87%
Reading package lists... 93%
Reading package lists... 93%
Reading package lists... 93%
Reading package lists... 93%
Reading package lists... 99%
Reading package lists... 99%
Reading package lists... 99%
Reading package lists... 99%
Reading package lists... Done
Building dependency tree... 0%
Building dependency tree... 0%
Building dependency tree... 50%
Building dependency tree... 50%
Building dependency tree
Reading state information... 0%
Reading state information... 0%
Reading state information... Done
The following additional packages will be installed:
ca-certificates libpsl5 libssl1.1 openssl publicsuffix
The following NEW packages will be installed:
ca-certificates libpsl5 libssl1.1 openssl publicsuffix wget
0 upgraded, 6 newly installed, 0 to remove and 4 not upgraded.
Need to get 2521 kB of archives.
After this operation, 7001 kB of additional disk space will be used.
0% [Working]
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libssl1.1 amd64 1.1.1-1ubuntu2.1~18.04.6 [1301 kB]
0% [1 libssl1.1 14.2 kB/1301 kB 1%]
45% [Working]
Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 openssl amd64 1.1.1-1ubuntu2.1~18.04.6 [614 kB]
45% [2 openssl 9404 B/614 kB 2%]
67% [Waiting for headers]
Get:3 http://archive.ubuntu.com/ubuntu bionic/main amd64 ca-certificates all 20180409 [151 kB]
68% [3 ca-certificates 29.6 kB/151 kB 20%]
76% [Waiting for headers]
Get:4 http://archive.ubuntu.com/ubuntu bionic/main amd64 libpsl5 amd64 0.19.1-5build1 [41.8 kB]
76% [4 libpsl5 17.4 kB/41.8 kB 42%]
80% [Working]
Get:5 http://archive.ubuntu.com/ubuntu bionic/main amd64 publicsuffix all 20180223.1310-1 [97.6 kB]
81% [5 publicsuffix 23.1 kB/97.6 kB 24%]
87% [Working]
Get:6 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 wget amd64 1.19.4-1ubuntu2.2 [316 kB]
87% [6 wget 21.3 kB/316 kB 7%]
100% [Working]
Fetched 2521 kB in 1s (3270 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libssl1.1:amd64.
(Reading database ...
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 4046 files and directories currently installed.)
Preparing to unpack .../0-libssl1.1_1.1.1-1ubuntu2.1~18.04.6_amd64.deb ...
Unpacking libssl1.1:amd64 (1.1.1-1ubuntu2.1~18.04.6) ...
Selecting previously unselected package openssl.
Preparing to unpack .../1-openssl_1.1.1-1ubuntu2.1~18.04.6_amd64.deb ...
Unpacking openssl (1.1.1-1ubuntu2.1~18.04.6) ...
Selecting previously unselected package ca-certificates.
Preparing to unpack .../2-ca-certificates_20180409_all.deb ...
Unpacking ca-certificates (20180409) ...
Selecting previously unselected package libpsl5:amd64.
Preparing to unpack .../3-libpsl5_0.19.1-5build1_amd64.deb ...
Unpacking libpsl5:amd64 (0.19.1-5build1) ...
Selecting previously unselected package publicsuffix.
Preparing to unpack .../4-publicsuffix_20180223.1310-1_all.deb ...
Unpacking publicsuffix (20180223.1310-1) ...
Selecting previously unselected package wget.
Preparing to unpack .../5-wget_1.19.4-1ubuntu2.2_amd64.deb ...
Unpacking wget (1.19.4-1ubuntu2.2) ...
Setting up libpsl5:amd64 (0.19.1-5build1) ...
Setting up publicsuffix (20180223.1310-1) ...
Setting up libssl1.1:amd64 (1.1.1-1ubuntu2.1~18.04.6) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Setting up openssl (1.1.1-1ubuntu2.1~18.04.6) ...
Setting up wget (1.19.4-1ubuntu2.2) ...
Setting up ca-certificates (20180409) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Updating certificates in /etc/ssl/certs...
133 added, 0 removed; done.
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for ca-certificates (20180409) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
--2020-05-30 21:50:35-- http://localhost/
Resolving localhost (localhost)... 127.0.0.1, 127.0.0.1, ::1
Connecting to localhost (localhost)|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 612 [text/html]
Saving to: 'STDOUT'
- 0%[ ] 0 --.-KB/s <!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
- 100%[===================>] 612 --.-KB/s in 0s
2020-05-30 21:50:35 (101 MB/s) - written to stdout [612/612]
Обратите внимание на самое начало, где у нас показывается версия бубна. Это та самая cat /etc/os-release из конфига.
И на самый конец, который показывает приветственную страницу веб-сервера. Как раз результат wget -O - http://localhost/, который по факту wget -O - http://localhost:80