2015-04-24 17 views
1

我有一個非常簡單的碼頭工人,compose.yml:泊塢窗,譜寫出/生成重複條目etc/hosts中

db: 
    build: docker/db 
    env_file: 
    - .env 
    ports: 
    - "5432" 

web: 
    build: . 
    env_file: 
    - .env 
    volumes: 
    - .:/home/app/emerson 
    ports: 
    - "80:80" 
    links: 
    - db 

Web容器啓動一個Rails應用程序。一切順利,但有一件事讓我感到困惑。看裏面的/ etc/Web容器的主機上,我看到以下條目:

172.17.0.10  db_1 
172.17.0.10  emerson_db_1 
172.17.0.10  db 

我希望分貝,因爲這是我鏈接到網絡容器容器,但哪兒來的其他人從哪裏來?僅供參考,這裏的的輸出泊塢窗,構成了

Creating emerson_db_1... 
Creating emerson_web_1... 
Attaching to emerson_db_1, emerson_web_1 
db_1 | The files belonging to this database system will be owned by user "postgres". 
db_1 | This user must also own the server process. 
db_1 | 
db_1 | The database cluster will be initialized with locale "en_US.utf8". 
db_1 | The default database encoding has accordingly been set to "UTF8". 
db_1 | The default text search configuration will be set to "english". 
db_1 | 
db_1 | Data page checksums are disabled. 
db_1 | 
db_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok 
db_1 | creating subdirectories ... ok 
db_1 | selecting default max_connections ... 100 
db_1 | selecting default shared_buffers ... 128MB 
db_1 | selecting dynamic shared memory implementation ... posix 
db_1 | creating configuration files ... ok 
web_1 | *** Running /etc/my_init.d/00_configure_nginx.sh... 
web_1 | *** Running /etc/my_init.d/00_regen_ssh_host_keys.sh... 
web_1 | No SSH host key available. Generating one... 
db_1 | ok 
db_1 | initializing pg_authid ... ok 
web_1 | Creating SSH2 RSA key; this may take some time ... 
db_1 | initializing dependencies ... ok 
web_1 | Creating SSH2 DSA key; this may take some time ... 
web_1 | Creating SSH2 ECDSA key; this may take some time ... 
web_1 | Creating SSH2 ED25519 key; this may take some time ... 
db_1 | creating system views ... ok 
db_1 | loading system objects' descriptions ... ok 
db_1 | creating collations ... ok 
db_1 | creating conversions ... ok 
db_1 | creating dictionaries ... ok 
db_1 | setting privileges on built-in objects ... ok 
web_1 | invoke-rc.d: policy-rc.d denied execution of restart. 
db_1 | creating information schema ... ok 
web_1 | *** Running /etc/my_init.d/30_presetup_nginx.sh... 
web_1 | *** Running /etc/rc.local... 
db_1 | loading PL/pgSQL server-side language ... ok 
web_1 | *** Booting runit daemon... 
web_1 | *** Runit started as PID 98 
db_1 | vacuuming database template1 ... ok 
db_1 | copying template1 to template0 ... ok 
db_1 | copying template1 to postgres ... ok 
web_1 | Apr 24 02:44:26 1d3b7bb27612 syslog-ng[105]: syslog-ng starting up; version='3.5.3' 
db_1 | syncing data to disk ... ok 
db_1 | 
db_1 | WARNING: enabling "trust" authentication for local connections 
db_1 | You can change this by editing pg_hba.conf or using the option -A, or 
db_1 | --auth-local and --auth-host, the next time you run initdb. 
db_1 | 
db_1 | Success. You can now start the database server using: 
db_1 | 
db_1 |  postgres -D /var/lib/postgresql/data 
db_1 | or 
db_1 |  pg_ctl -D /var/lib/postgresql/data -l logfile start 
db_1 | 
db_1 | **************************************************** 
db_1 | WARNING: No password has been set for the database. 
db_1 |   This will allow anyone with access to the 
db_1 |   Postgres port to access your database. In 
db_1 |   Docker's default configuration, this is 
db_1 |   effectively any other container on the same 
db_1 |   system. 
db_1 |   
db_1 |   Use "-e POSTGRES_PASSWORD=password" to set 
db_1 |   it in "docker run". 
db_1 | **************************************************** 
db_1 | 
db_1 | PostgreSQL stand-alone backend 9.4.1 
db_1 | backend> statement: ALTER USER "postgres" WITH SUPERUSER ; 
db_1 | 
web_1 | ok: run: /etc/service/nginx-log-forwarder: (pid 118) 0s 
db_1 | backend> 
db_1 | No PostgreSQL clusters exist; see "man pg_createcluster" ... (warning). 
db_1 | 
db_1 | backend> ******************************************* 
db_1 | LOG: database system was shut down at 2015-04-24 02:44:28 UTC 
db_1 | LOG: database system is ready to accept connections 
db_1 | LOG: autovacuum launcher started 
web_1 | [ 2015-04-24 02:44:27.9386 119/7f4c07f13780 agents/Watchdog/Main.cpp:538 ]: Options: { 'analytics_log_user' => 'nobody', 'default_group' => 'nogroup', 'default_python' => 'python', 'default_ruby' => '/usr/bin/ruby', 'default_user' => 'nobody', 'log_level' => '0', 'max_pool_size' => '6', 'passenger_root' => '/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini', 'passenger_version' => '4.0.58', 'pool_idle_time' => '300', 'temp_dir' => '/tmp', 'union_station_gateway_address' => 'gateway.unionstationapp.com', 'union_station_gateway_port' => '443', 'user_switching' => 'true', 'web_server_passenger_version' => '4.0.58', 'web_server_pid' => '107', 'web_server_type' => 'nginx', 'web_server_worker_gid' => '33', 'web_server_worker_uid' => '33' } 
web_1 | [ 2015-04-24 02:44:27.0007 122/7f0c3eb9a780 agents/HelperAgent/Main.cpp:650 ]: PassengerHelperAgent online, listening at unix:/tmp/passenger.1.0.107/generation-0/request 
web_1 | [ 2015-04-24 02:44:28.1065 127/7f5e5b4377c0 agents/LoggingAgent/Main.cpp:321 ]: PassengerLoggingAgent online, listening at unix:/tmp/passenger.1.0.107/generation-0/logging 
web_1 | [ 2015-04-24 02:44:28.1072 119/7f4c07f13780 agents/Watchdog/Main.cpp:728 ]: All Phusion Passenger agents started! 

但只有兩個容器泊塢窗PS -a輸出:

CONTAINER ID  IMAGE    COMMAND    CREATED    STATUS    PORTS       NAMES 
1d3b7bb27612  emerson_web:latest "/sbin/my_init"  About an hour ago Up About an hour 443/tcp, 0.0.0.0:80->80/tcp emerson_web_1  
0c047c3ce103  emerson_db:latest "/docker-entrypoint. About an hour ago Up About an hour 0.0.0.0:49156->5432/tcp  emerson_db_1  

此外,我還看到重複的環境變量在Web容器中,對應於db,db_1和emerson_db_1前綴。

回答

2

他們來自1.0之前的docker-compose,其中多個db實例以_1,_2模式命名。

PR 364引入鏈接名稱(默認情況下爲鏈接服務的名稱)作爲要連接的主機名,而不是使用環境變量。

有與_x添加到每個容器實例仍然別名,這可能是個問題(Issue 472: Hostnames with underscore fails in ruby URI validation

目前的答案是:

可以在docker-compose.yml使用該服務的名稱作爲主機名,它不包含任何下劃線
你也可以添加一個別名到你的容器的鏈接,它應該允許你訪問它作爲別名。

在撰寫1.3版本時,應該支持將你的容器命名爲任何你想要的東西,這會讓這個更明顯。