Q&A

책을 따라하다가 막히는 부분이 있나요?
질문을 남겨주세요.

p.573까지 진행한 현재 docker-compose up이 작동하지 않습니다.

2 years, 7 months ago

kuj4455 kuj4455

services.db.volumes.1 type is required이란 메시지가 콘솔에 뜨면서 사이트 접속이 되질 않네요.

docker-compose up 뿐만 아니라 docker-compose build도 같은 이유로 작동이 되지 않고 있습니다.

아래는 현재 p.564~p.573까지 진행한 코드 내용입니다.

1. Dockerfile

# pull official base image
FROM python:3.8-slim-buster

# set work directory
WORKDIR /usr/src/app

# set enviroment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

COPY . /usr/src/app/
# install dependencies
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

2. docker-compose.yml

version: '3'

services:
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./:/usr/src/app/
ports:
- 8000:8000
env_file:
- ./.env.dev
depends_on:
- db
db:
image: postgres:12.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
- environment:
- POSTGRES_USER=do_it_django_db_user
- POSTGRES_PASSWORD=do_it_django_db_password
- POSTGRES_DB=do_it_django_dev
volumes:
postgres_data:

3. .end.dev

DEBUG = 1
SECRET_KEY = **************************************
DJANGO_ALLOWED_HOSTS = localhost 127.0.0.1 [::1]
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=do_it_django_dev
SQL_USER=do_it_django_db_user
SQL_PASSWORD=do_it_django_db_password
SQL_HOST=db
SQL_PORT=5432

4. settings.py 중 일부

SECRET_KEY = os.environ.get('SECRET_KEY', '**************************************')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = int(os.environ.get('DEBUG', 1))

if os.environ.get('DJANGO_ALLOWED_HOSTS'):
ALLOWED_HOSTS = os.environ.get('DJANGO_ALLOWED_HOSTS').split(' ')
else:
ALLOWED_HOSTS = []
DATABASES = {
'default': {
'ENGINE': os.environ.get("SQL_ENGINE", 'django.db.backends.sqlite3'),
'NAME': os.environ.get("SQL_DATABASE", os.path.join(BASE_DIR, 'db.sqlite3')),
'USER': os.environ.get("SQL_USER", 'user'),
'PASSWORD': os.environ.get("SQL_PASSWORD", 'password'),
'HOST': os.environ.get("SQL_HOST", 'localhost'),
'PORT': os.environ.get("SQL_PORT", '5432'),
}
}

5. requirements.txt

asgiref==3.5.0
asttokens==2.0.5
backcall==0.2.0
beautifulsoup4==4.10.0
black==22.1.0
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.12
click==8.0.3
colorama==0.4.4
cryptography==36.0.1
decorator==5.1.1
defusedxml==0.7.1
Django==3.2
django-allauth==0.49.0
django-crispy-forms==1.14.0
django-extensions==3.1.5
django-markdownx==3.0.1
executing==0.8.2
idna==3.3
importlib-metadata==4.11.2
ipython==8.0.1
jedi==0.18.1
Markdown==3.3.6
matplotlib-inline==0.1.3
mypy-extensions==0.4.3
oauthlib==3.2.0
parso==0.8.3
pathspec==0.9.0
pickleshare==0.7.5
Pillow==9.0.1
platformdirs==2.5.0
prompt-toolkit==3.0.28
pure-eval==0.2.2
pycparser==2.21
Pygments==2.11.2
PyJWT==2.3.0
python3-openid==3.2.0
pytz==2021.3
requests==2.27.1
requests-oauthlib==1.3.1
six==1.16.0
soupsieve==2.3.1
sqlparse==0.4.2
stack-data==0.1.4
tomli==2.0.1
traitlets==5.1.1
typing_extensions==4.1.0
tzdata==2021.5
urllib3==1.26.8
wcwidth==0.2.5
zipp==3.7.0
cryptography

sungyong
sungyong   2 years, 7 months ago

안녕하세요. 들여쓰기가 잘못 된 것 같습니다. 

위에 써 놓은거 보면, environment 부분이 들여쓰기가 되어 있네요. 책을 보고 아래처럼 수정해보세요. 

  db:
image: postgres:12.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_USER=do_it_django_db_user
- POSTGRES_PASSWORD=do_it_django_db_password
- POSTGRES_DB=do_it_django_dev


Updated: March 16, 2022, 9:13 a.m.

Leave a Comment:
목록보기
Search
  • 자유게시판
  • Q&A