Saleor: [Docker] The SECRET_KEY setting must not be empty.

Created on 25 Nov 2018  Â·  28Comments  Â·  Source: mirumee/saleor

What I'm trying to achieve

Install and run Saleor on Docker in production

Steps to reproduce the problem

  1. docker build -t mystorefront .
  2. docker run mystorefront:latest

What I expected to happen

Launch the store on port 8000

Screenshots

image

System information
Operating system: UBUNTU 18.04
Browser:

General questions:
What are the env variables that docker is using and how can I change them?

All 28 comments

For local development you might want to use docker-compose up

Env variables are listed here: https://docs.getsaleor.com/en/latest/gettingstarted/configuration.html

Hi @Pacu2, this is not for development, it's for production.

I'm really confused here and I don't know how to deploy using docker. I'm still getting this error.
What are the correct steps please?

Please try docker run -e SECRET_KEY=*** -e DATABASE_URL=*** -p 8000:8000 saleor

Are those parameters (-e DATABASE_URL=* ) referring to docker's postgres?

It can be any postgres database owned by you. You can run postgresl via docker or buy postgreql from cloud provider.

But isn't that docker's purpose? To have everything in a single container that doesn't affect the system you're working on?
I really don't want to run postgres outside docker as I think it'd become harder to maintain..

Sure, then you can run another postgresql container via docker. You can not setup multiple services in one container. So I would recommend you use docker-compose. Refer https://docs.getsaleor.com/en/latest/customization/docker.html

Thanks for your comment, but isn't that, per say, for development and not for production?

Or you can run docker run -d -e POSTGRES_USER=saleor -e POSTGRES_PASSWORD=saleor postgres:9.6-alpine to startup your postgresql service. Then you database url would be postgres://saleor:saleor@localhost:5432/saleor

IMO, docker-compose can be used for production, only if you setup correctly, such as appropriate environment varialbles.

Ok, let's see what the maintainers have to say in this.
Thanks for your efforts.

Are you sure you have properly set environmental variable SECRET_KEY? Does command env | grep SECRET_KEY produce non empty result?

Small side note:

But isn't that docker's purpose? To have everything in a single container that doesn't affect the system you're working on?

Not really. Container comes in and out all the time ("bacterias"), but some data (storage, database) are usually desired to stay the same, regarding application code changes, so you want to have them maintained outside the container.
You may want to take a look at:
https://docs.docker.com/storage/#more-details-about-mount-types
and probably voulmes subarticle.

Yes, the env command gives the secret_key I set. But I noticed it got reset every time I ssh to my server.
Should I set it inside docker or the ubuntu server?

I added the export command to .bash_profile and now it's persisted. But so is the problem :)
@akjanik, can you reproduce this on your end?

@jxltom is right. You need to set the environment variable from outside the Docker. Either give it explicitly when starting docker (docker run -e SECRET_KEY=soverysecret ...) or export it in your startup script and tell Docker to use the value (docker run -e SECRET_KEY ...).

Thanks for the confirmation.
Thanks to @jxltom too. I'll try and get back to you.
More stress for a detailed documentation.

UPDATE, the server runs without issues, but when I try to connect to ip:8000 the connection is refused.
Any idea why? I checked iptables, explicitly allowd tcp on 8000 but still connection refused.

It should be accessed in 127.0.0.1:8000.

For accessed via 0.0.0.0:8000, probably you need to setup proxy if your server is running behind a reverse proxy such as nginx

I don't think it works:
curl: (7) Failed to connect to 127.0.0.1 port 8000: Connection refused

Have you you added -p 8000:8000 in docker run?

Besides, are you sure you have never set PORT environment varialble other than 8000?

I didn't change anything in that. it's by default.
EXPOSE 8000
ENV PORT 8000

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
381caaf33755        saleor:latest       "uwsgi /app/saleor/w…"   24 minutes ago      Up 24 minutes       8000/tcp            infallible_torvalds

It's clear it's running on 8000 but not reachable?

No, it should like this:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ccefc28b869a saleor "uwsgi /app/saleor/w…" 11 seconds ago Up 10 seconds 0.0.0.0:8000->8000/tcp serene_volhard

You HAVE TO add -p 8000:8000 when running by docker run such as docker run -e SECRET_KEY=<SECRET_KEY> -e DATABASE_URL=<DATABASE_URL> -p 8000:8000 saleor

Interesting. I'm sorry but the deployment documentation lacks content big time.
Thanks, I'll try it out.

It works thanks a lot.
Why do you think the initial config didn't work out?

It is because EXPOSE only make the port be accessed within docker. -p which is publish argument make it can be accessed anywhere.

Awersome. Thanks a lot for all the help.

Was this page helpful?
0 / 5 - 0 ratings