Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docker] The SECRET_KEY setting must not be empty. #3325

Closed
asennoussi opened this issue Nov 25, 2018 · 28 comments
Closed

[Docker] The SECRET_KEY setting must not be empty. #3325

asennoussi opened this issue Nov 25, 2018 · 28 comments

Comments

@asennoussi
Copy link

asennoussi commented Nov 25, 2018

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?

@Pacu2
Copy link
Contributor

Pacu2 commented Nov 25, 2018

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

@asennoussi
Copy link
Author

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

@asennoussi
Copy link
Author

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?

@jxltom
Copy link
Contributor

jxltom commented Nov 26, 2018

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

@asennoussi
Copy link
Author

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

@jxltom
Copy link
Contributor

jxltom commented Nov 26, 2018

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

@asennoussi
Copy link
Author

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..

@jxltom
Copy link
Contributor

jxltom commented Nov 26, 2018

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

@asennoussi
Copy link
Author

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

@jxltom
Copy link
Contributor

jxltom commented Nov 26, 2018

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

@jxltom
Copy link
Contributor

jxltom commented Nov 26, 2018

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

@asennoussi
Copy link
Author

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

@akjanik
Copy link
Contributor

akjanik commented Nov 26, 2018

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.

@asennoussi
Copy link
Author

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?

@asennoussi
Copy link
Author

asennoussi commented Nov 26, 2018

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?

@patrys
Copy link
Member

patrys commented Nov 26, 2018

@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 ...).

@asennoussi
Copy link
Author

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

@asennoussi
Copy link
Author

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.

@jxltom
Copy link
Contributor

jxltom commented Nov 26, 2018

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

@asennoussi
Copy link
Author

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

@jxltom
Copy link
Contributor

jxltom commented Nov 26, 2018

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

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

@asennoussi
Copy link
Author

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

@asennoussi
Copy link
Author

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?

@jxltom
Copy link
Contributor

jxltom commented Nov 26, 2018

No, it should like this:

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

@asennoussi
Copy link
Author

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

@asennoussi
Copy link
Author

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

@jxltom
Copy link
Contributor

jxltom commented Nov 26, 2018

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

@asennoussi
Copy link
Author

Awersome. Thanks a lot for all the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants