将docker-compose.yml中的端口更改为主机上的旧暴露端口

时间:2018-09-02 11:40:04

标签: wordpress docker docker-compose portforwarding

我正在尝试通过docker安装Wordpress,但主机上的转发端口很奇怪。

我首先将docker-compose.yml配置为运行wordpress和mysql:

version: '2'

services:
  wordpress:
    image: wordpress:latest
    links:
      - database:mysql
    environment:
      - WORDPRESS_DB_USER=root
      - WORDPRESS_DB_NAME=mydbname
      - WORDPRESS_TABLE_PREFIX=ap_
      - WORDPRESS_DB_PASSWORD=password
      - WORDPRESS_DB_HOST=database
    restart: unless-stopped
    ports:
     - 9090:80
    working_dir: /var/www/html
    volumes:
     - ./wordpress:/var/www/html/
  database:
   image: mysql:latest
   environment:
     - MYSQL_ROOT_PASSWORD=password
     - MYSQL_DATABASE=mydbname
     - MYSQL_USER=root
     - MYSQL_PASSWORD=password
   restart: unless-stopped
   ports:
     - "3306:3306"
   volumes:
     - db_data:/var/lib/mysql
volumes:
 db_data: {}

但是我意识到之后我已经在该端口9090

上运行了另一个独立的容器

因此,我改用一个空闲的公开端口7878(以及其他多个空闲端口)。

当我尝试浏览刚刚安装在localhost:7878上的Wordpress时,我被重定向到localhost:9090

我试图通过删除另一个独立的容器甚至停止Docker守护程序来解决它,但浏览器仍将我的端口转发到旧的9090。我还尝试删除docker网络,但到目前为止没有成功。

我的配置:

Host machine: 
MacBook Pro mid-2015
macOS High Sierra Version 10.13.6

Docker:
docker version
Client:
 Version:           18.06.0-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        0ffa825
 Built:             Wed Jul 18 19:05:26 2018
 OS/Arch:           darwin/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.0-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       0ffa825
  Built:            Wed Jul 18 19:13:46 2018
  OS/Arch:          linux/amd64
  Experimental:     true

Docker-compose:
docker-compose version 1.22.0, build f46880f
docker-py version: 3.4.1
CPython version: 3.6.4
OpenSSL version: OpenSSL 1.0.2o  27 Mar 2018

0 个答案:

没有答案