[DOCKER] Build Python + django + nginx + MySQL environment using docekr

Build a Web system development environment using Docker

Reasons to use Docker

Struggling to build an environment on your own

I posted about environment construction in another article. I had a very difficult time at that time. (Rather, I was defeated ...)

"This time, you can also build an environment using Docker."

So, when I deepen my understanding of building my own environment, I will revenge again.

Why Docker?

First, deepen your understanding of Docker. I referred to the following article. https://koni.hateblo.jp/entry/2017/01/28/150522 https://knowledge.sakura.ad.jp/13265/ https://www.kagoya.jp/howto/rentalserver/container-03/

What is Docker-compose?

Docker compose is a function that automates the procedure for building and executing a service consisting of multiple containers, making it easier to manage. With Docker compose, you can prepare a compose file and execute the command once to read the settings from that file and start all container services.

reference https://qiita.com/TsutomuNakamura/items/7e90e5efb36601c5bc8a

# yum install git
#~~~Copy the part from github according to the environment you build
# git clone https://github.com/~~~~~~

Cloning into 'docker-django'...
remote: Enumerating objects: 315, done.
remote: Counting objects: 100% (315/315), done.
remote: Compressing objects: 100% (96/96), done.
remote: Total 315 (delta 214), reused 308 (delta 211), pack-reused 0
Receiving objects: 100% (315/315), 5.81 MiB | 1.48 MiB/s, done.
Resolving deltas: 100% (214/214), done.

The hierarchy after the download is completed is as follows.

# ll
total 0
drwxr-xr-x. 8 root root 99 Dec 17 07:36 docker-django

Docker installation

Regarding the installation, I referred to the following article. https://zenn.dev/ymasaoka/articles/install-docker-centos-7

Check the version of Docker.

# docker --version
-bash: docker: command not found

Of course, it is not installed, so I will install it.

The official website states that only the maintenance version of CentOS is supported. https://docs.docker.com/engine/install/centos/

Therefore, first update CentOS to the latest version. It will take about 5 minutes.

# yum update

Installation of official repositories

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Install Docker CE

yum install -y docker-ce docker-ce-cli containerd.io

Version confirmation

# docker --version
Docker version 20.10.1, build 831ebea

Start Docker

# systemctl start docker

Autostart settings

# systemctl enable docker

Install Docker-compose

I referred to the following official website. https://docs.docker.com/compose/install/

# sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   651  100   651    0     0   4672      0 --:--:-- --:--:-- --:--:--  4683
100 11.6M  100 11.6M    0     0  1663k      0  0:00:07  0:00:07 --:--:-- 1983k

Confirmation of Docker-compose installation

# docker-compose --version
docker-compose version 1.27.4, build 40524192

Docker-compose permissions

When I first Docker-compose up, I got an error about permissions

# docker-compose up
-bash: /usr/local/bin/docker-compose: Permission denied

Grant authority. Grant execute permission with + x. I referred to the following article for granting authority. https://qiita.com/ntkgcj/items/6450e25c5564ccaa1b95

sudo chmod +x /usr/local/bin/docker-compose

Run Docker-compose

# docker-compose up

[Memo] Add -d at the end to start it in the background.

Start the container with docker-compose.

Only the last part of the execution result is described. (There should be no error ?? Confirm at the next work!)

Digest: sha256:b1d09e9718890e6ebbbd2bc319ef1611559e30ce1b6f56b2e3b479d9da51dc35
Status: Downloaded newer image for nginx:1.13
Creating docker-django_db_1 ... done
Creating docker-django_python_1 ... done
Creating docker-django_nginx_1  ... done
Attaching to docker-django_db_1, docker-django_python_1, docker-django_nginx_1
db_1      | 2020-12-17 08:26:22+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.32-1debian10 started.
db_1      | 2020-12-17 08:26:23+09:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1      | 2020-12-17 08:26:23+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.32-1debian10 started.
db_1      | 2020-12-16T23:26:23.591372Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1      | 2020-12-16T23:26:23.598365Z 0 [Note] mysqld (mysqld 5.7.32) starting as process 1 ...
db_1      | 2020-12-16T23:26:23.601759Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1      | 2020-12-16T23:26:23.601790Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1      | 2020-12-16T23:26:23.601798Z 0 [Note] InnoDB: Uses event mutexes
db_1      | 2020-12-16T23:26:23.601806Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1      | 2020-12-16T23:26:23.601814Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1      | 2020-12-16T23:26:23.601824Z 0 [Note] InnoDB: Using Linux native AIO
db_1      | 2020-12-16T23:26:23.602178Z 0 [Note] InnoDB: Number of pools: 1
db_1      | 2020-12-16T23:26:23.602323Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1      | 2020-12-16T23:26:23.613511Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1      | 2020-12-16T23:26:23.626984Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1      | 2020-12-16T23:26:23.629335Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1      | 2020-12-16T23:26:23.651521Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1      | 2020-12-16T23:26:23.750055Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1      | 2020-12-16T23:26:23.760013Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1      | 2020-12-16T23:26:23.819358Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1      | 2020-12-16T23:26:23.820262Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1      | 2020-12-16T23:26:23.820287Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1      | 2020-12-16T23:26:23.820537Z 0 [Note] InnoDB: Waiting for purge to start
db_1      | 2020-12-16T23:26:23.871301Z 0 [Note] InnoDB: 5.7.32 started; log sequence number 13003109
db_1      | 2020-12-16T23:26:23.873814Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1      | 2020-12-16T23:26:23.874376Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1      | 2020-12-16T23:26:23.950993Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1      | 2020-12-16T23:26:23.951023Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
db_1      | 2020-12-16T23:26:23.963368Z 0 [Warning] CA certificate ca.pem is self signed.
db_1      | 2020-12-16T23:26:23.963432Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
db_1      | 2020-12-16T23:26:23.974071Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1      | 2020-12-16T23:26:23.974182Z 0 [Note] IPv6 is available.
db_1      | 2020-12-16T23:26:23.974204Z 0 [Note]   - '::' resolves to '::';
db_1      | 2020-12-16T23:26:23.974242Z 0 [Note] Server socket created on IP: '::'.
db_1      | 2020-12-16T23:26:24.040014Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1      | 2020-12-16T23:26:24.067064Z 0 [Note] InnoDB: Buffer pool(s) load completed at 201217  8:26:24
db_1      | 2020-12-16T23:26:24.350990Z 0 [Note] Event Scheduler: Loaded 0 events
db_1      | 2020-12-16T23:26:24.351267Z 0 [Note] mysqld: ready for connections.
db_1      | Version: '5.7.32'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

Contents of docker-compose.yml

version: '3'
services:
    nginx:
       image: nginx:1.13
       ports:
          - "80:80"
       volumes:
          - ./nginx/conf:/etc/nginx/conf.d
       depends_on:
          - python
    db:
        image: mysql:5.7
        ports:
          - "3306:3306"
        environment:
          MYSQL_ROOT_PASSWORD: mysql
          MYSQL_DATABASE: mysql
          MYSQL_USER: mysql
          MYSQL_PASSWORD: mysql
          TZ: 'Asia/Tokyo'
        volumes:
          - ./mysql:/var/lib/mysql
          - ./sql:/docker-entrypoint-initdb.d
    python:
        build: ./python
        command: uwsgi --socket :8001 --module app.wsgi --py-autoreload 1 --logt
o /tmp/mylog.log
        volumes:
           - ./src:/code
           - ./static:/static
        expose:
           - "8001"
        depends_on:
           - db

Access from browser

After starting with docker-compose, try accessing from the web. http: // [IP address] http: // [IP address]: 80

Access screen (isn't it working?)

image.png

When I accessed it, there was a reaction like this on Tera Term.

nginx_1   | 103.5.140.159 - - [17/Dec/2020:22:45:03 +0000] "GET / HTTP/1.1" 500 32 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" "-"
nginx_1   | 103.5.140.159 - - [17/Dec/2020:22:45:04 +0000] "GET /favicon.ico HTTP/1.1" 500 32 "http://140.227.75.4/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" "-"

ALLOWD HOST was not set.

./src/mysite/settings.py

ALLOWED_HOSTS = ['[IP address]',]

I can't access it yet. docker-ps Let's see the state using.

# docker ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS          PORTS                               NAMES
f4ef866fe8e8   nginx:1.13             "nginx -g 'daemon of…"   24 hours ago     Up 3 minutes    0.0.0.0:80->80/tcp                  docker-django_nginx_1
6c7057c4c1fd   docker-django_python   "uwsgi --socket :800…"   24 hours ago     Up 3 minutes    8001/tcp                            docker-django_python_1
ba3f3cfef45d   mysql:5.7              "docker-entrypoint.s…"   24 hours ago     Up 3 minutes    0.0.0.0:3306->3306/tcp, 33060/tcp   docker-django_db_1
[root@qsbbvu1t docker-django]#

Since STATUS is up, it seems to be up.

Docker migration

I wasn't doing the migration work. Work by referring to the following site. https://qiita.com/kenkono/items/6221ad12670d1ae8b1dd#django%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%AE%E5%AE%9F%E8%A1%8C

The following error occurred. It's related to MySQL. pymysql doesn't yet support the new version of django.

# docker-compose run python ./manage.py makemigrations

raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.8.0.

The same error occurred. After checking, pymysql does not support django 2.2 in the first place.

To solve ① Insert mysqlclient instead of pymysql (django recommended) ② Decrease the version of django from 2.2 to 2.1

Install sqlclient

Lowering the version of django is not security-friendly. So this time I decided to use mysqlclient instead of pymysql.

The error stated that mysqlclient version 1.3.13 or higher was required. Therefore, I changed the contents of requirements.txt to the following.

# vi requirements.txt

Django==2.2.13
uwsgi==2.0.17
mysqlclient==1.3.13

migration

Migration has the following meanings. To migrate and convert the environment and platform such as programs, data, and OS.

Move to the directory where manage.py exists and execute the following.

[root@qsbbvu1t src]# docker-compose run python ./manage.py makemigrations

Below, an error occurred.

Creating docker-django_python_run ... done
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 361, in execute
    self.check()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 390, in check
    include_deployment_checks=include_deployment_checks,
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/usr/local/lib/python3.6/site-packages/django/core/checks/urls.py", line 10, in check_url_config
    if getattr(settings, 'ROOT_URLCONF', None):
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 79, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 66, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 157, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/code/app/settings.py", line 14, in <module>
    import pymysql
ModuleNotFoundError: No module named 'pymysql'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 336, in run_from_argv
    connections.close_all()
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 219, in close_all
    for alias in self:
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 213, in __iter__
    return iter(self.databases)
  File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 147, in databases
    self._databases = settings.DATABASES
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 79, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 66, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 157, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/code/app/settings.py", line 14, in <module>
    import pymysql
ModuleNotFoundError: No module named 'pymysql'

The description of pymysql seems to be the cause of the error. I will rewrite it to mysqlclient.

# vi settings.py

Commented out pymysql and added import of mysqlclient.

import os
import mysqlclient
# import pymysql

# connect mysql
#pymysql.install_as_MySQLdb()
mysqlclient.install_as_MySQLdb()

I will try migrating again.

An error has occurred.

# docker-compose run python ./manage.py makemigrations
Creating docker-django_python_run ... done
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 361, in execute
    self.check()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 390, in check
    include_deployment_checks=include_deployment_checks,
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/core/checks/registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/usr/local/lib/python3.6/site-packages/django/core/checks/urls.py", line 10, in check_url_config
    if getattr(settings, 'ROOT_URLCONF', None):
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 79, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 66, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 157, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/code/app/settings.py", line 14, in <module>
    import mysqlclient
ModuleNotFoundError: No module named 'mysqlclient'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 336, in run_from_argv
    connections.close_all()
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 219, in close_all
    for alias in self:
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 213, in __iter__
    return iter(self.databases)
  File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 147, in databases
    self._databases = settings.DATABASES
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 79, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 66, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 157, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/code/app/settings.py", line 14, in <module>
    import mysqlclient
ModuleNotFoundError: No module named 'mysqlclient'

Hmm. does not go well. After investigating, I found information that does not require import mysqlclient to be described in settings.py. https://zerofromlight.com/blogs/detail/29/

I'll give it a try.

# vi settings.py
import os
#import mysqlclient
# import pymysql

# connect mysql
#pymysql.install_as_MySQLdb()
#mysqlclient.install_as_MySQLdb()
# docker-compose run python ./manage.py makemigrations
Creating docker-django_python_run ... done
No changes detected

Did it work? Perform migration.

# docker-compose run python ./manage.py migrate
Creating docker-django_python_run ... done
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK

Oh, I feel like I was able to go.

Launch docker container

# docker-compose build
db uses an image, skipping
nginx uses an image, skipping
Building python
Step 1/7 : FROM python:3.6
 ---> 4a03e5e8adde
Step 2/7 : ENV PYTHONUNBUFFERED 1
 ---> Using cache
 ---> 8c1a88d570f3
Step 3/7 : RUN mkdir /code
 ---> Using cache
 ---> 7f012356f716
Step 4/7 : WORKDIR /code
 ---> Using cache
 ---> 647e9247446c
Step 5/7 : ADD requirements.txt /code/
 ---> Using cache
 ---> 31fc46edeab4
Step 6/7 : RUN pip install -r requirements.txt
 ---> Using cache
 ---> ec091df899d8
Step 7/7 : ADD . /code/
 ---> Using cache
 ---> ff87162e0f0d

Successfully built ff87162e0f0d
Successfully tagged docker-django_python:latest
# docker-compose up

No particular error occurred and stopped at the following. (Command cannot be entered)

db_1      | Version: '5.7.32'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

I can't enter commands, so I'll start it in the background.

# docker-compose up -d
Starting docker-django_db_1 ... done
Starting docker-django_python_1 ... done
Starting docker-django_nginx_1  ... done

Check if it can be started. Since STATUS is Up, it seems to be okay.

# docker-compose ps
         Name                   Command           State           Ports
--------------------------------------------------------------------------------
docker-django_db_1       docker-entrypoint.sh     Up      0.0.0.0:3306->3306/tcp
                         mysql ...                        , 33060/tcp
docker-django_nginx_1    nginx -g daemon off;     Up      0.0.0.0:80->80/tcp
docker-django_python_1   uwsgi --socket :8001     Up      8001/tcp
                         --mod ...

http: // [IP address]: [Port number (I am 80)] Connect from the web with.

image.png

I finally got access! !!

Apply CSS

When I went to the administrator screen (http: // [IP address]/admin), it was confirmed that CSS was not applied.

image.png

Apply CSS.

# vi settings.py

Added STATIC_ROOT.

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = '/static'

Execute the following command.

# docker-compose run python ./manage.py collectstatic
Creating docker-django_python_run ... done

119 static files copied to '/static'.

Refresh your browser page. CSS has been applied to make it easier to see.

image.png

Recommended Posts

Build Python + django + nginx + MySQL environment using docekr
Build a Python virtual environment using venv (Django + MySQL ①)
Build Mysql + Python environment with docker
Initial setting of environment using Docker-compose + Django + MySQL + Nginx + uwsgi
Build NGINX + NGINX Unit + MySQL environment with Docker
Build Django + NGINX + PostgreSQL development environment with Docker
Build Python3.5 + matplotlib environment on Ubuntu 12 using Anaconda
Build a Django environment on Raspberry Pi (MySQL)
[Python] Build a Django development environment with Docker
Deploy Django apps on Ubuntu + Nginx + MySQL (Build)
Create Nginx + uWSGI + Python (Django) environment with docker
Try using tensorflow ① Build python environment and introduce tensorflow
Quickly build a Python Django environment with IntelliJ
Build a Django development environment using pyenv-virtualenv on Mac
How to build a Django (python) environment on docker
Build a Python environment on your Mac using pyenv
Build a Python development environment using pyenv on MacOS
Build python3 environment with ubuntu 16.04
Build Python environment on Windows
Build python environment with direnv
[ev3dev × Python] Build ev3dev development environment
Build python environment on windows
Build a Python environment offline
Build an environment for machine learning using Python on MacOSX
Build a Django development environment with Docker! (Docker-compose / Django / postgreSQL / nginx)
[Django] Memo to create an environment of Django + MySQL + Vue.js [Python]
Python practice_Virtual environment setup ~ Django installation
Build python virtual environment with virtualenv
Build a go environment using Docker
Install nginx python postgresql using apt-get
Install Python framework django using pip
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
Build a python3 environment on CentOS7
Python3.6 environment construction (using Win environment Anaconda)
[Docker] Build an environment of python (Flask) + GraphQL (graphene) + MySQL (sqlalchemy)
Build a local development environment for Lambda + Python using Serverless Framework
# 3 Build a Python (Django) environment on AWS EC2 instance (ubuntu18.04) part2
Try using virtualenv, which can build a virtual environment for Python
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
Build and try an OpenCV & Python environment in minutes using Docker
Build a Python execution environment using GPU with GCP Compute engine
Learning history to participate in team application development with Python ~ Build Docker / Django / Nginx / MariaDB environment ~
Build an environment for Blender built-in Python
Python development environment for macOS using venv 2016
Build Jupyter Lab (Python) environment with Docker
Python 2.7, 3.4, 3.5 extension module build environment on Windows
Method to build Python environment in Xcode 6
Using venv in Windows + Docker environment [Python]
Build Python3 and OpenCV environment on Ubuntu 18.04
Build a python environment on MacOS (Catallina)
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Easy construction]
CSS environment created in 10 minutes using Django
[Python] Create a Batch environment using AWS-CDK
I want to build a Python environment
Create Python + uWSGI + Nginx environment with Docker
[Mac] Build a Python 3.x environment at the fastest speed using Docker
Build Python environment with Anaconda on Mac
Python execution server construction (Python + uWSGI + Django + Nginx)
Install Python3 using pythonz under macports environment
Build a python virtual environment with pyenv
Build Python development environment (pythonz, virtualenv, direnv)