【Docker】Docker部署爬虫实战

本文介绍了在Ubuntu 18.04上安装Docker 19.03.5的过程,以及如何使用Docker部署爬虫。详细讲解了创建Dockerfile、构建镜像、启动容器、管理镜像和容器的命令,包括日志查看、资源限制设置等。还提到了Docker系统的监控和清理策略,以及Docker在爬虫运维中的应用。
摘要由CSDN通过智能技术生成

环境

系统:ubuntu18.04
docker:19.03.5

Docker概述

推荐每个容器只运行一个进程

安装docker

1.卸载已安装的docker

 sudo apt autoremove docker
 
 sudo apt autoremove docker-engine
 
 sudo apt autoremove docker.io

2.执行自动安装docker的脚本

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

安装成功后出现:

Client: Docker Engine - Community
.
.
.
  
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

  sudo usermod -aG docker dell

Remember that you will have to log out and back in for this to take effect!

WARNING: Adding a user to the "docker" group will grant the ability to run
         containers which can be used to obtain root privileges on the
         docker host.
         Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
         for more information.

此时,docker CE 的稳定(stable)版本已经安装在系统中。

3.新建docker用户组,并将当前用户加入

sudo groupadd docker
sudo usermod -aG docker 当前用户的用户名

4.初始化docker的一些设置

官方示例:https://docs.docker.com/engine/reference/commandline/dockerd/#/linux-configuration-file

以下分别设置了docker镜像源,docker日志驱动和每个容器的日志最大值,日志文件最大数,Docker数据存储目录(默认/var/lib/docker)

sudo vim /etc/docker/daemon.json
# 写入如下内容并保存
{
    
"registry-mirrors": [
    "https://hub-mirror.c.163.com",
    "https://registry.aliyuncs.com",
    "https://registry.docker-cn.com",
    "https://docker.mirrors.ustc.edu.cn"
  ],
"log-driver":"json-file",
"log-opts": {
   "max-size":"500m", "max-file":"3"}
}
"data-root":"/data/docker"

5.设置docker开机自启动,并重启docker使配置生效

sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl daemon-reload
sudo systemctl restart docker

6.验证docker的启动

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
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值