Docker撰写|虚拟主机 [英] Docker Compose | Virtual Hosts
问题描述
我的代码有什么问题?
Whats wrong in my code? thanks in advance!
我正在尝试为docker容器设置虚拟主机。
在本地主机上:8000可以正常工作,但是当我尝试通过http://borgesmelo.local/访问时,错误ERR_NAME_NOT_RESOLVED出现了,可能丢失了什么?
I'm trying to set up a virtual host for my docker container. On localhost: 8000 works perfectly, but when I try to access through http: //borgesmelo.local/ the error ERR_NAME_NOT_RESOLVED appears, what can be missing?
这是我的-> docker-compose.yml
This is my -> docker-compose.yml
version: '3.3'
services:
borgesmelo_db:
image: mariadb:latest
container_name: borgesmelo_db
restart: always
volumes:
- ./mariadb/:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: My@159#Sql
MYSQL_PASSWORD: My@159#Sql
borgesmelo_ws:
image: richarvey/nginx-php-fpm:latest
container_name: borgesmelo_ws
restart: always
volumes:
- ./public/:/var/www/html
ports:
- "8000:80"
borgesmelo_wp:
image: wordpress:latest
container_name: borgesmelo_wp
volumes:
- ./public/:/var/www/html
restart: always
environment:
VIRTUAL_HOST: borgesmelo.local
WORDPRESS_DB_HOST: borgesmelo_db:3306
WORDPRESS_DB_PASSWORD: My@159#Sql
depends_on:
- borgesmelo_db
- borgesmelo_ws
borgesmelo_phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
container_name: borgesmelo_phpmyadmin
links:
- borgesmelo_db
ports:
- "8001:80"
environment:
- PMA_ARBITRARY=1
borgesmelo_vh:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "8002:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
networks:
default:
external:
name: nginx-proxy
这是我的房东文件(/ etc / hosts)[macOS]
This is my hosts file (/etc/hosts) [macOS]
#DOCKER
127.0.0.1:8000 borgesmelo.local
推荐答案
Hosts文件不支持端口,因为它是用于名称查找的只要。因此,您必须将主机文件设置为:
Hosts file doesn't support ports as it is for name lookup only. So you would have to set your hosts file to:
127.0.0.1 borgesmelo.local
然后通过 http://borgesmelo.local:8000
访问您的应用程序。
Then access your application with http://borgesmelo.local:8000
.
如果您正在侦听端口8000,因为端口80上已经有其他端口,则可以考虑使用nginx作为反向代理,然后可以根据< a href = http://nginx.org/en/docs/http/server_names.html rel = nofollow noreferrer> server_name 。这样,您可以通过端口80访问多个应用程序。如果要处理Docker容器,请考虑研究 Traefik 作为反向代理。
If you are listening on port 8000 because you already have something else on port 80, then consider using nginx as a reverse proxy and then you can route to different applications based on the server_name. That way, you can access multiple applications through port 80. If you're dealing with docker containers, then consider looking into Traefik as a reverse proxy.
这篇关于Docker撰写|虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!