0

I'am trying to run a project that uses Django and uWSGI in a Docker container. But I'm new to Docker and uWSGI so I'm not quite sure how I'm supposed to do it.

First I built the project with this command:

docker build -t saleor .

Then I ran it:

docker run --env SECRET_KEY="<the key>" -p 4000:80 saleor

And this is what I get:

[uWSGI] getting INI configuration from /app/saleor/wsgi/uwsgi.ini
[uwsgi-static] added mapping for /static => /app/static
*** Starting uWSGI 2.0.15 (64bit) on [Tue Dec 19 14:02:19 2017] ***
compiled with version: 4.9.2 on 19 December 2017 09:11:22
os: Linux-4.10.0-42-generic #46~16.04.1-Ubuntu SMP Mon Dec 4 15:57:59 UTC 2017
nodename: 88adfd3f2e93
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /app
detected binary path: /usr/local/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
your memory page size is 4096 bytes
detected max file descriptor number: 1048576
building mime-types dictionary from file /etc/mime.types...547 entry found
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address :8000 fd 3
Python version: 3.5.4 (default, Dec 12 2017, 16:43:39)  [GCC 4.9.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x12277b0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145536 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x12277b0 pid: 1 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1)
spawned uWSGI worker 1 (pid: 10, cores: 1)

Now I don't know what I am supposed to do. Usually with Django applications, I would just check localhost:4000 in my browser. But it doesn't work in this case and I get nothing. So what am I supposed to do?

Zanna
  • 72,312

3 Answers3

1

I just understood something. "docker run" only starts a single container. But some projects use multiple containers for different services(like this one) and for them, docker-compose should be used. The problem was that the database was just in another container. So using "docker-compose up" solved the issue.

Although I now have another issue, which seems to need a peek inside the database. Does anyone know how I can log in to a database inside a container?

0

When you run the command

docker build -t saleor .

It means that you build with Dockerfile while there is a user and group added on the process.

RUN groupadd -r saleor && useradd -r -g saleor saleor

as well as the directory is owned by that user/group: saleor/saleor

RUN mkdir -p /app/media /app/static  && chown -R saleor:saleor /app/

You need to add: --user saleor:saleor to docker run, so the uWSGI will not run as root

docker run --env SECRET_KEY="<the key>" -p 4000:8000 --user saleor:saleor saleor

The localhost:4000 should then run normally. Here is the output:

[uWSGI] getting INI configuration from /app/saleor/wsgi/uwsgi.ini
[uwsgi-static] added mapping for /static => /app/static
*** Starting uWSGI 2.0.17.1 (64bit) on [Tue Mar 12 15:10:03 2019] ***
compiled with version: 6.3.0 20170516 on 08 February 2019 17:14:12
os: Linux-4.4.0-142-generic #168~14.04.1-Ubuntu SMP Sat Jan 19 11:26:28 UTC 2019
nodename: xxxxxx
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /app
detected binary path: /usr/local/bin/uwsgi
your processes number limit is 524288
your memory page size is 4096 bytes
detected max file descriptor number: 524288
building mime-types dictionary from file /etc/mime.types...554 entry found
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address :4000 fd 3
Python version: 3.6.8 (default, Feb  6 2019, 03:44:09)  [GCC 6.3.0 20170516]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x5XX
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 364600 bytes (356 KB) for 4 cores
*** Operational MODE: preforking ***
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x5XX pid: 1 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1)
spawned uWSGI worker 1 (pid: 9, cores: 1)
spawned uWSGI worker 2 (pid: 10, cores: 1)
spawned uWSGI worker 3 (pid: 11, cores: 1)
spawned uWSGI worker 4 (pid: 12, cores: 1)
eQ19
  • 101
0

I'm not used to docker. Do you know where do you pull the source from ?

https://github.com/mirumee/saleor-demo

For example here, I can see in the Dockerfile

EXPOSE 8000
ENV PORT 8000

And in Django the server points to 8000 too (see docker-compose.yml)

I would try :

docker run --env SECRET_KEY="<the key>" -p 4000:8000 saleor

and listen to port 4000

curl http://localhost:4000

Port 5432 seems to be postgres port

Thomas PEDOT
  • 119
  • 4