Docker:我无法将80以外的端口映射到我的WordPress容器 [英] Docker: I can't map ports other than 80 to my WordPress container

查看:402
本文介绍了Docker:我无法将80以外的端口映射到我的WordPress容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在计算机上映射一些随机端口,例如 localhost:7006 到我的WordPress Docker容器的端口80 。当我将WordPress的端口从 80:80 到 7006:80 不仅停止在 localhost(端口80)但也不要响应 localhost:7006

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 文件如下所示:

        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:


推荐答案

经过一番研究,我发现WordPress容器设置了端口一次,因为它需要保存URL( localhost:7006 ),因为我要保留数据库数据。

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.

我运行了 docker-compose up 使用默认端口 80:80 配置一次,导致 localhost:80 localhost 保存在数据库中。因此,当我再次更改端口并运行 docker-compose up 时,我实际上弄乱了用WordPress容器存储在链接的mysql db容器中的URL。

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.

我跑了 docker-compose down --volumes (这会导致持久的数据破坏)
,然后更改了docker-compse.yml中我的WordPress容器的端口。再次运行以下命令,使我的WordPress容器在端口7006( localhost:7006 )上运行。
docker-compose up

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




重要提示:我只是在玩docker,所以我不想保存
卷数据。任何想要保留其数据的人都不得使用
docker-compose down --volumes

它现在正在所需的端口上运行

It's running on the desired port now

这篇关于Docker:我无法将80以外的端口映射到我的WordPress容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆