Docker:我无法将 80 以外的端口映射到我的 WordPress 容器 [英] Docker: I can't map ports other than 80 to my WordPress container
问题描述
我想在我的计算机上映射一些随机端口,例如localhost:7006
到我的 WordPress docker 容器的 port 80
.当我将 WordPress 的端口从 80:80
更改为 7006:80
它不仅在 localhost(port 80)
上停止工作,而且在 localhost:7006
上也没有响应.
docker-compose.yml
文件如下所示:
版本:'3'服务:WordPress:依赖于取决于:- D b图片:wordpress:4.7.1重启:总是卷:- ./wp-content:/var/www/html/wp-content环境:WORDPRESS_DB_HOST:数据库:3306WORDPRESS_DB_PASSWORD:p4ssw0rd!端口:- 80:80 # 暴露 http 和 https- 8443:443网络:- wp_nwkD b:图片:mysql:5.7重启:总是卷:- db_data:/var/lib/mysql环境:MYSQL_ROOT_PASSWORD:p4ssw0rd!网络:- wp_nwkphpmyadmin:依赖于取决于:- D b图片:phpmyadmin/phpmyadmin重启:总是端口:- 7005:80环境:PMA_HOST:分贝MYSQL_ROOT_PASSWORD:p4ssw0rd!网络:- wp_nwk网络:wp_nwk:卷:数据库数据:
经过一番研究,我发现 WordPress 容器设置了它的端口一次,因为它需要保存 URL(localhost:7006
) 在数据库中,因为我正在持久化数据库数据.
我使用导致 localhost:80
或 的默认端口
保存在数据库中.因此,当我再次更改端口并运行 80:80
配置运行了一次 docker-compose up
localhostdocker-compose up
时,我实际上将存储在链接 mysql db 容器中的 URL 与我的 WordPress 容器混淆了.
我运行了 docker-compose down --volumes
(这会导致持久数据破坏)然后在 docker-compse.yml 中更改了我的 WordPress 容器的端口.再次运行以下命令在端口 7006 (localhost:7006
) 上创建了我的 WordPress 容器.docker-compose up
wordpress:依赖于取决于:- D b图片:wordpress:4.7.1重启:总是卷:- ./wp-content:/var/www/html/wp-content环境:WORDPRESS_DB_HOST:数据库:3306WORDPRESS_DB_PASSWORD:p4ssw0rd!端口:- 7006:80 # 暴露 http 和 https- 8443:443网络:- wp_nwk
<块引用>
重要提示:我只是在玩 docker,所以我不想保存我的卷数据.任何想要保留其数据的人都不得使用docker-compose down --volumes
它现在正在所需的端口上运行
I want to map some random port on my computer e.g. localhost:7006
to my WordPress docker container's port 80
.When I change the port of WordPress from 80:80
to 7006:80
it's not only stops working on localhost(port 80)
but also don't respond on localhost:7006
.
docker-compose.yml
file looks like this:
version: '3'
services:
wordpress:
depends_on:
- db
image: wordpress:4.7.1
restart: always
volumes:
- ./wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: p4ssw0rd!
ports:
- 80:80 # Expose http and https
- 8443:443
networks:
- wp_nwk
db:
image: mysql:5.7
restart: always
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: p4ssw0rd!
networks:
- wp_nwk
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 7005:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: p4ssw0rd!
networks:
- wp_nwk
networks:
wp_nwk:
volumes:
db_data:
After a bit of research I found out that the WordPress container sets it's ports once since it needs to save the URLs(localhost:7006
) in the db because I am persisting the db data.
I ran the docker-compose up
once with the default port 80:80
configuration which caused the localhost:80
or localhost
to be saved in the db. So when I changed the ports again and ran docker-compose up
, I actually messed up the URLs that are stored in the linked mysql db container with my WordPress container.
I ran docker-compose down --volumes
(this causes the persisted data destruction)
and then changed the ports of my WordPress container in docker-compse.yml. Running the following command again created my WordPress container live on port 7006 (localhost:7006
).
docker-compose up
wordpress:
depends_on:
- db
image: wordpress:4.7.1
restart: always
volumes:
- ./wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: p4ssw0rd!
ports:
- 7006:80 # Expose http and https
- 8443:443
networks:
- wp_nwk
IMPORTANT: I am just playing with docker, so I don't want to save my volumes data. Anyone wanting to keep their data must not use the
docker-compose down --volumes
It's running on the desired port now
这篇关于Docker:我无法将 80 以外的端口映射到我的 WordPress 容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!