我的docker-compose.yml内容如下:
version: "3"
services:
my_server:
build: .
restart: always
depends_on:
mysql:
condition: service_started
ports:
- 9999:9999
links:
- mysql
mysql:
image: mysql:latest # mysql:oracle
restart: always
container_name: mysql
command:
- --lower_case_table_names=1
ports:
- 3306:3306
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/setup.sql
environment:
- MYSQL_ROOT_PASSWORD=123456
Dockerfile内容如下:
FROM sanicframework/sanic:3.8-latest
WORKDIR /sanic/my_server
COPY . /sanic/my_server
COPY . .
RUN pip install -r requirements.txt
EXPOSE 9999
CMD ["python", "main.py"]
使用docker-compose.yml部署项目时候,提示
RuntimeError:‘cryptography’ package isrequired for sha256_password or caching_sha2_password,
出现的原因是mysql8.0+版本使用了新的密码校验插件,需要安装cryptography这个库,
当你在requirement.txt加上cryptography==39.0.1后,重新运行docker compose up这条命令时候,又出现如下错误
也就是说,安装cryptography这个库的时候,下载依赖出现问题,解决这个问题就是安装一些必备的库,在Dockerfile文件添加以下内容
RUN apk update
RUN apk --update add gcc musl-dev libffi-dev openssl-dev
RUN apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo
RUN pip install -r requirements.txt
EXPOSE 9999
RUN apk del --purge gcc musl-dev libffi-dev openssl-dev
就可以解决问题,完整的dockerfile如下:
FROM sanicframework/sanic:3.8-latest
WORKDIR /sanic/my_server
COPY . /sanic/my_server
COPY . .
RUN apk update
RUN apk --update add gcc musl-dev libffi-dev openssl-dev
RUN apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo
RUN pip install -r requirements.txt
EXPOSE 9999
RUN apk del --purge gcc musl-dev libffi-dev openssl-dev
CMD ["python", "main.py"]