大网数据广告活动
服务器运维问答

Nginx Docker container always restarting

· 52CE 我爱测

My current docker-compose.yml looks like this: 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…

问题原文

原帖链接 · Jaquarh · CC BY-SA 4.0

My current docker-compose.yml looks like this:

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

However, when I run a docker-compose up --build -d and then run docker-compose ps I can see that my nginx container is always restarting:

$ 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

I have tried using the tty: true as stated on previous ServerFault questions but this has not fixed the issue as seen above. Any solutions to this?

已采纳解答

原帖链接 · Jaquarh · CC BY-SA 4.0

Upon executing docker compose logs test_site_nginx, thanks to a user on Redit, I saw this error:

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

Turns out I was missing a semi-colon ending a configuration line when declaring

user www-data; # <-- I did not have the ;

After a restart, the service booted as expected and my logs where running fine.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-01-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。