Docker for beginner

本文探讨了Docker如何简化应用从开发到部署的过程,通过创建Dockerfile和docker-compose.yml实现依赖管理和快速启动。重点讲解了Docker容器的优势,如轻量级、环境隔离,并介绍了关键配置文件如Django示例。

Doker

Why docker

Development -> Testing -> Deploy
We need to give everything to testing team including dependency
But it is very hard becasue the entire OS need to ship to testing team

Previous
We use virtual image

What is Docker

give virtual image is too big and is wasting

Come up of containers taht runs on top of OS

Creating App on Docker

  1. create docker-compose.yml

  2. Dockerfile
    FROM python:3
    ENV PYTHONUNBUFFERED 1
    RUN mkdir /app
    WORKING /app
    COPY requirements.txt /app/
    RUN pip install -r requirements.txt

  3. requirements.txt
    Django==2.2

  4. docker-compose.yml
    version: ‘3’
    services:
    web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
    - .:/app
    ports:
    - “8000:8000”

  5. docker-compose run web django-admin strartprojet mysite .

  6. docker-compose up

Windows PowerShell 版权所有(C) Microsoft Corporation。保留所有权利。 安装最新的 PowerShell,了解新功能和改进!https://aka.ms/PSWindows PS C:\Windows\system32> wsl beginner88@localhost:/mnt/c/Windows/system32$ docker version The command 'docker' could not be found in this WSL 2 distro. We recommend to activate the WSL integration in Docker Desktop settings. For details about using Docker Desktop with WSL 2, visit: https://docs.docker.com/go/wsl2/ beginner88@localhost:/mnt/c/Windows/system32$ # 在 PowerShell 中运行 beginner88@localhost:/mnt/c/Windows/system32$ wsl -l -v wsl: command not found beginner88@localhost:/mnt/c/Windows/system32$ wsl --set-version <发行版名称> 2 -bash: 发行版名称: No such file or directory beginner88@localhost:/mnt/c/Windows/system32$ # 验证 Docker 客户端连接 beginner88@localhost:/mnt/c/Windows/system32$ docker --version docker run hello-world The command 'docker' could not be found in this WSL 2 distro. We recommend to activate the WSL integration in Docker Desktop settings. For details about using Docker Desktop with WSL 2, visit: https://docs.docker.com/go/wsl2/ beginner88@localhost:/mnt/c/Windows/system32$ beginner88@localhost:/mnt/c/Windows/system32$ # 验证完整功能 beginner88@localhost:/mnt/c/Windows/system32$ docker run hello-world The command 'docker' could not be found in this WSL 2 distro. We recommend to activate the WSL integration in Docker Desktop settings. For details about using Docker Desktop with WSL 2, visit: https://docs.docker.com/go/wsl2/ beginner88@localhost:/mnt/c/Windows/system32$
03-08
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值