Docker默认安装路径是在C盘,Windows中修改Docker**默认安装****路径方法:
1.先创建 D:Program FilesDocker 目录
2.运行命令,创建链接
mklink /J “C:Program FilesDocker” “D:codeSoftwareDocker”
3.点击exe安装完成后,查看版本
docker -v
4.运行docker的hello world
docker run hello-world
查看镜像
docker images
5.docker部署flask例子
5.1 新建Flaskdemo 新建虚拟环境
python -m venv venv
激活
.venvScriptsactivate
安装Flask
pip install Flask
app.py代码
from flask import Flask
app = Flask(__name__)
@app.route(/)
def index():
return “hello,learn docker”
if __name__ == __main__:
app.run(host=”0.0.0.0″,port=7001,debug=True)
5.2 创建DockerFile文件
注:放在项目的根目录下,然后根据里面的指令来配置具体项目所需的环境
这里使用的是vscode里面的插件docker
Ctrl Shift P,输入docker:add
即可依据框架选择,然后自动生成
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.8-slim
EXPOSE 5001
# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
# Install pip requirements
COPY requirements.txt .
RUN python -m pip install -r requirements.txt
WORKDIR /app
COPY . /app
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
RUN adduser -u 5678 –disabled-password –gecos “” appuser
暂无评论内容