Ubuntu16.04折腾的docker之旅

安装,安装可以看我上一遍文章

Ubuntu16.04下离线安装docker和使用docker

配置

1、加速器daoclound注册和登录
然后在ubuntu的终端运行类似这样的命令

curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://940b3fc8.m.daocloud.io

2、然后docker 修改存储路径(不是通过软链接)

//停止docker 服务
service docker stop
//创建配置文件和添加脚本命令
 mkdir /etc/systemd/system/docker.service.d
 cd /etc/systemd/system/docker.service.d
  vim docker.conf
//添加如下脚本
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --graph=/mnt/docker-data --storage-driver=overlay
//重新加载daemon-reload
systemctl daemon-reload
//重启docker
systemctl restart docker
//查看信息
docker info

配置scrapy爬虫环境

1、下载一个镜像

docker pull ubuntu:latest

用该镜像运行一个容器名为scrapy

docker run -it --name scrapy 16508e5c265d /bin/bash

2、进入容器后做的事情

apt-get update
apt-get install iputils-ping
apt-get install wget
apt-get install python3
apt-get install python3-pip
apt-get install python3-dev

apt-get install make
#apt-get install  build-depgcc
#apt-get  install  build-essential
 #apt-get install libxml2-dev libxslt1-dev
 #apt-get install libgsl0-dev
 #apt-get install libffi-dev
 #apt-get install libssl-dev
 pip3 install scrapy
exit //退出容器

3、退出容器后需要保存起来
保存命令

docker commit -m "ubuntu with scrapy" -a "tiramisu" aa97ba3292ce tiramisu/ubuntu:scrapy

其中,
-m指定说明信息;
-a指定用户信息;
aa97ba3292ce代表容器的id;
tiramisu/ubuntu:vim指定目标镜像的用户名、仓库名和 tag 信息。tiramisu是你运行命令的时候使用自己注册Docker时的用户名。
因为这是daocloud的账户,只有付费用户才能push,这里就不push了,想Push的同学可以去docker hub官网注册一个,这是免费的。

4、删除旧的镜像,保留刚刚保存的镜像

docker ps -a //查看刚刚容器
docker rm container_id //删除基于旧镜像的容器
docker rmi image_id //删除旧的镜像

进入刚刚保存的镜像

docker run -it --name scrapy 1e597ab9b673 /bin/bash

5、镜像和容器的导出,然后拷贝到其他电脑上用,因为没有云服务啊。

//将镜像存储
docker save nginx:latest > /root/docker-images/nginx.tar

//导入镜像文件
docker load --input /root/docker-images/nginx.tar

//通过符号的方式来导入
docker load < /root/docker-images/nginx.tar

容器导出

//导出容器furious_bell
docker export furious_bell > /home/myubuntu-export-1204.tar
//导入容器furious_bell
docker import - /home/myubuntu-export-1204.tar

查看链接

docker 修改存储路径(不是通过软链接)
四个修改Docker默认存储位置的方法
Docker_入门?只要这篇就够了!(纯干货适合0基础小白)
在 docker 之间导出导入镜像
Docker的镜像导出与导入与拷贝 -yellowcong

猜你喜欢

转载自blog.csdn.net/lovexlsforever/article/details/82320482