【发布时间】:2018-06-12 21:20:12
【问题描述】:
是否可以在 localhost 以外的其他主机上运行 docker 映像?
端口80 和443 总是被其他应用程序占用,所以我想知道是否可以运行它,例如192.168.0.100,然后设置 /etc/hosts 文件为该 IP 地址分配一个名称。
我试图设置extra_hosts 选项,但我不确定它是否是为此而设计的。无论哪种方式,我都没有成功设置它,因为Value should be a mapping, not an array 存在一些问题。
我想值得一提的是,我在 macOS 上使用 docker-compose 运行所有内容。提前谢谢你。
docker-compose.yaml
version: "2"
services:
php:
build: ./php
volumes:
- ../develog.org:/usr/share/nginx/html
depends_on:
- memcached
nginx:
build: ./nginx
ports:
- 4001:80
- 4002:443
volumes_from:
- php:ro
depends_on:
- php
memcached:
image: memcached:alpine
networks:
default:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.1.0.0/16
nginx 配置
map $scheme $ssl_request {
https "https";
}
server {
# support http and ipv6
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
# support https and ipv6
listen 443 default_server ssl;
listen [::]:443 ipv6only=on default_server ssl;
# path to web directory
root /web/;
index index.html index.htm;
# domain or subdomain
server_name localhost;
include self-signed.conf;
include ssl-params.conf;
}
【问题讨论】:
-
可以在docker compose中指定远程端口
ports: - "8983:8983"
标签: docker docker-compose dockerfile docker-for-mac