开源web框架django知识总结(十四)

开源web框架django知识总结(十四)

容器化方案Docker

  • 涉及到相同的工作是否需要重复做
  • 避免相同的工作重复做是容器化技术应用之一。

1. Docker介绍

Docker通常用于如下场景:
  • web应用的自动化打包和发布;

  • 自动化测试和持续集成、发布;

  • 在服务型环境中部署和调整数据库或其他的后台应用;

  • Docker中文社区文档

  • Docker 是一个开源的软件部署解决方案。

  • Docker 也是轻量级的应用容器框架。

  • Docker 就像一个盒子,里面可以装很多物件,如果需要某些物件,可以直接将该盒子拿走,而不需要从该盒子中一件一件的取。

  • Docker 是一个"客户端-服务端(C/S)"架构程序。

    • 客户端只需要向服务端发出请求,服务端处理完请求后会返回结果。

Docker 包括三个基本概念:

  • 镜像(Image)
    • Docker的镜像概念类似于虚拟机里的镜像,是一个只读的模板,一个独立的文件系统,包括运行容器所需的数据,可以用来创建新的容器。
    • 例如:一个镜像可以包含一个完整的 ubuntu 操作系统环境,里面仅安装了MySQL或用户需要的其它应用程序。
  • 容器(Container)
    • Docker容器是由Docker镜像创建的运行实例,类似VM虚拟机,支持启动,停止,删除等。
    • 每个容器间是相互隔离的,容器中会运行特定的应用,包含特定应用的代码及所需的依赖文件。
  • 仓库(Repository)
    • Docker的仓库功能类似于Github,是用于托管镜像的。

2. Docker安装(ubuntu 18.04)

1,更新ubuntu的apt源索引

sudo apt-get update

2, 安装包允许apt通过HTTPS使用仓库,安装证书
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

在这里插入图片描述
如果出现上面报错,解决方法:

sudo rm /var/lib/dpkg/updates/*
sudo dpkg --configure -a
sudo apt-get update
sudo apt-get upgrade

注意:sudo apt-get upgrade中间会有个提示选择,选择“N”
在这里插入图片描述

解决方法:

sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/dpkg/lock-frontend

再次执行:

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

添加docker的官方GPGkey(此步可能一次不能通过,多执行几次)

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

添加docker源

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

安装 docker ce

  1. 更新包索引
sudo apt-get update

2.安装docker

sudo apt-get install docker-ce

中间可能会卡在MySQL升级上:

Checking if update is needed.
This installation of MySQL is already upgraded to 5.7.33, use --force if you still need to run mysql_upgrade

使用另一个窗口,查看端口进程:

ps aux |grep mysql
kill -9 MySQL进程

3.启动docker

# 启动docker
sudo service docker start

# 停止docker
sudo service docker stop

# 重启docker
sudo service docker restart

4.检测是否安装成功

sudo docker run hello-world

安装成功会出现如下输出:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
<
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

主打Python

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值