1

I'm trying to setup an nginx container via docker-compose. I have a custom configuration I'd like to use. I make the config available on a volume that is shared with the container.

nginx:
      volumes:
      - shared:/shared
      image: nginx
      ports:
      - "8080:80"
      - "443:443"
      command: /bin/bash -c ./shared/nginx_test.conf

Here is the configuration file:

daemon off;

http {
    server {
    location / {
        root /shared/data/www;
    }

    location /images/ {
        root /data;
    }
    }
}

When I do a docker-compose up, I get errors for each line in the config that say the command is not found. e.g. ./shared/nginx_test.conf: line 1: daemon: command not found, ./shared/nginx_test.conf: line 3: http: command not found and so on.

I tried following the guide here. Any ideas on why the commands are not found by nginx?

1 Answer 1

3

You're trying to run a script file with bash -c, do you see that? That's not what you want. (The error messages say the content of ./shared/nginx_test.conf is not understood, which Bash interprets as terminal commands.)

You probably want to run something like nginx -g daemon off as a command, and append the configuration file as an argument:

nginx:
    # ...
    command: nginx -c ./shared/nginx_test.conf -g "daemon off;"

References:

Sign up to request clarification or add additional context in comments.

1 Comment

Ahh, I think I got confused by this line from their docker doc. command: /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'" I'll try out your suggestion soon.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.