We will introduce it using the sample application (feedback-api).
`Although it is an article on Mac environment, the procedure is the same for Windows environment. Please read and try the environment-dependent part. ``
After reading this article to the end, you will be able to:
No. | Overview | keyword |
---|---|---|
1 | docker settings | install, Dockerfile, docker-compose.yml |
2 | start docker | docker run, docker-compose up |
environment | Ver. |
---|---|
macOS Catalina | 10.15.3 |
Python | 3.7.3 |
Docker | 19.03.8 |
I think that understanding will deepen if you read while actually following the implementation contents and source code. Please use it by all means.
tree.sh
/
│── config/
├── app/
└── Dockerfiles/
├── app/
│ ├── Dockerfile
│ ├── docker-compose.yml
│ └── entrypoint.sh
├── docker_compose_up.sh
└── docker_run.sh
command_line.sh
~$ brew install docker
~$ brew cask install docker
FROM python:3.7
RUN mkdir /code
WORKDIR /code
ADD entrypoint.sh /code/entrypoint.sh
ADD app/ /code
RUN pip install --upgrade pip --no-cache-dir
RUN pip install -r requirements.txt --no-cache-dir
EXPOSE 5000
ENV PYTHONPATH "${PYTHONPATH}:/code/"
ENV FLASK_APP "/code/run.py"
CMD ["/code/entrypoint.sh"]
Dockerfiles/app/entrypoint.sh
#!/bin/sh
sleep 5
flask db init
flask db migrate
flask db upgrade
flask run --host=0.0.0.0 --port=5000
docker(flask) <-> localhost(postgres)
Keep postgres start
on localhost.
Dockerfiles/docker_run.sh
#!/bin/sh
docker stop $(docker ps -q)
docker rm $(docker ps -q -a)
# docker rmi $(docker images -q) -f
rsync -av --exclude=app/tests* app Dockerfiles/app
docker build -t feedback-api Dockerfiles/app
docker run -it -p 5000:5000 feedback-api:latest
command_line.sh
Dockerfiles/docker_run.sh
docker(flask) <-> docker(postgres)
Keep postgres on localhost stop
.
Dockerfiles/docker_compose_up.sh
#!/bin/sh
docker stop $(docker ps -q)
docker rm $(docker ps -q -a)
# docker rmi $(docker images -q) -f
rsync -av --exclude=app/tests* app Dockerfiles/app
docker-compose -f Dockerfiles/app/docker-compose.yml up --build
Dockerfiles/app/docker-compose.yml
version: '3'
services:
docker_postgres:
image: postgres:11.5
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: feedback
POSTGRES_INITDB_ARGS: --encoding=UTF-8
app:
build: .
depends_on:
- docker_postgres
ports:
- 5000:5000
environment:
ENV_CONFIG: docker
SQLALCHEMY_POOL_SIZE: 5
SQLALCHEMY_MAX_OVERFLOW: 10
SQLALCHEMY_POOL_TIMEOUT: 30
command_line.sh
Dockerfiles/docker_compose_up.sh
Recommended Posts