我现在的docker-compose.yml
样子是这样的:
version: '3'
services:
testsite-nginx:
image: nginx:alpine
container_name: test_site_nginx
restart: unless-stopped
tty: true
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./example.co.uk:/var/www
ports:
# I do want to map it to port 8080 on my local machine, not 80
- 8080:80
networks:
- app-network
testsite-mysql:
image: mysql:5.7.22
container_name: test_site_mysql
restart: unless-stopped
tty: true
ports:
# I do want to map it to port 3309 on my local machine, not 3306
- 3309:3306
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: somethingreallysecure
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./example.co.uk/mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
testsite-app:
build:
context: .
image: example.co.uk/app
container_name: test_site_app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
- ./example.co.uk:/var/www
depends_on:
- testsite-nginx
- testsite-mysql
networks:
- app-network
networks:
app-network:
driver: bridge
volumes:
dbdata:
driver: local
但是,当我运行 adocker-compose up --build -d
然后运行时docker-compose ps
,我可以看到我的 nginx 容器始终在重新启动:
$ docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------
test_site_app docker-php-entrypoint php-fpm Up 9000/tcp
test_site_mysql docker-entrypoint.sh mysqld Up 0.0.0.0:3309->3306/tcp
test_site_nginx /docker-entrypoint.sh ngin ... Restarting
我尝试使用tty: true
之前 ServerFault 问题中提到的方法,但这并没有解决上述问题。有什么解决办法吗?
答案1
执行后docker compose logs test_site_nginx
,感谢 Redit 上的一位用户,我看到了此错误:
2021/01/20 12:37:18 [emerg] 1#1: invalid number of arguments in "user" directive in /etc/nginx/nginx.conf:2
nginx: [emerg] invalid number of arguments in "user" directive in /etc/nginx/nginx.conf:2
事实证明,我在声明时遗漏了一个分号来结束配置行
user www-data; # <-- I did not have the ;
重新启动后,服务按预期启动并且我的日志运行良好。