我有两个目录,除了分配的端口外,每个目录都运行相同的docker build。我无法连接到本地主机中的容器之一。
运行docker ps命令后,我看到80/tcp
被添加到第二个recipe-blog
容器中。下面是我的yml文件,它没什么疯狂的,只需设置一个运行php的数据库(我的管理员)并将其连接到WordPress安装即可。我还附加了docker ps
命令的图像。
services:
# Database
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- wpsite
# phpmyadmin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '9090:90'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: password
networks:
- wpsite
# Wordpress
wordpress:
depends_on:
- db
image: wordpress:5.3.0
ports:
- '9000:90'
restart: always
working_dir: /var/www/html
volumes:
- ./wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
networks:
- wpsite
networks:
wpsite:
volumes:
db_data: {}
wp-content:
- finalsandbox_ I
可以再次正常连接,但我无法连接到recipe-blog_
。这两个yml文件之间的唯一区别在于,对于recipe-blog_
,我将端口更改为9090:90
而不是8080:80
,将端口更改为9000:90
而不是8000:80
。
先谢谢了。
答案 0 :(得分:1)
它对我有用,例如
version: "3"
services:
# Database
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- wpsite
# phpmyadmin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- '9090:80'
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: wordpress
networks:
- wpsite
# Wordpress
wordpress:
depends_on:
- db
image: wordpress:5.3.0
ports:
- '9000:80'
restart: always
working_dir: /var/www/html
volumes:
- ./wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
networks:
- wpsite
networks:
wpsite:
volumes:
db_data: {}
wp-content:
将90分配的所有端口更改为80。
docker-compose up -d
与您的浏览器收藏夹一起连接到http://127.0.0.1:9000和http://127.0.0.1:9090