2
Dockerでは、docker network create usta_network
コマンドで新しいネットワークを作成し、このネットワークをdocker-compose.ymlファイルのサービス宣言で参照しました。Nginx設定ファイルのコンテナ名にアクセス
今はコンテナの名前でサービスをpingできますが、Nginx Upstream宣言の中でコンテナの名前を参照するにはどうすればいいですか?コンテナ間でアクセスするには、どの方法が最適ですか? nginxの
version: '2'
services:
nginx-main:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- /var/log/nginx:/var/log/nginx
container_name: nginx_main
networks:
default:
external:
name: usta_network
./nginx.conf
ユーザnginxのため
docker.compose。
http {
server {
listen 80;
index index.php index.html index.htm;
server_name example.org www.example.org;
location/{
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://rahmanusta_upstream;
}
}
upstream rahmanusta_upstream {
server rahmanusta_wp:6565;
}
}
のMySQL +ワードプレス
version: '2'
services:
mysql-db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: pass
MYSQL_DATABASE: mysql_db
MYSQL_USER: root
MYSQL_PASSWORD: pass
container_name: mysql_db
rahmanusta-wp:
depends_on:
- mysql-db
image: wordpress:latest
ports:
- "6565:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: pass
container_name: rahmanusta_wp
volumes:
db_data:
networks:
default:
external:
name: usta_network
ドッカーネットワーク用ドッカー-構成usta_network
[
{
"Name": "usta_network",
"Id": "b971429c1ddcfa791bdfff0a6f9463ab9cfb9ae04ba6a3aa60ce08ca11d0a5ab",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.20.0.0/16",
"Gateway": "172.20.0.1/16"
}
]
},
"Internal": false,
"Containers": {
"16cc89ca548fe90fb8ed9431d8e9633c341373344304ec3320acee1a81090709": {
"Name": "rahmanusta_wp",
"EndpointID": "d310cbf9617958226d36d5f9e0d804c113093097669b1d5ae8bed90d31dfca2f",
"MacAddress": "02:42:ac:14:00:03",
"IPv4Address": "172.20.0.3/16",
"IPv6Address": ""
},
"5b0f7a7d95b23b6e69b17f85ebff5d652bdbcba305755169c6b9f78199fbf346": {
"Name": "mysql_db",
"EndpointID": "d2c304b450ce96d309ef51319aa42336bb742d99db095e98e129e547aee820c3",
"MacAddress": "02:42:ac:14:00:02",
"IPv4Address": "172.20.0.2/16",
"IPv6Address": ""
},
"addf3c475fcfd5566b3d1c4b4a951f78978c07265211746f79711f38c5cd9649": {
"Name": "nginx_main",
"EndpointID": "3f4106184dbe805c509011c3dc42c673c85fcf2eb08441a5ecf24b9c5c68e2d4",
"MacAddress": "02:42:ac:14:00:04",
"IPv4Address": "172.20.0.4/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
おかげを検査。