栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

干净的docker镜像

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

干净的docker镜像

看看是否存在/etc/docker/daemon.json文件,不存在则新建一个vi /etc/docker/daemon.json输入

{"registry-mirrors" : [
    "https://registry.docker-cn.com",
    "https://docker.mirrors.ustc.edu.cn",
    "http://hub-mirror.c.163.com",
    "https://cr.console.aliyun.com/",
    "https://xxxx.mirror.aliyuncs.com"
]}

https://xxxx.mirror.aliyuncs.com这个是阿里的容器镜像服务,登录后找到对应ubuntu的加速地址就是它

docker pull ubuntu:18.04
docker pull centos:7
docker pull centos:8

就能很快的下载到干净的ubuntu18的镜像,只有63.2MB

xxx@xxx:/data/docker$ docker images
REPOSITORY        TAG            IMAGE ID       CREATED         SIZE
ubuntu            18.04          fdf0753c97a9   3 days ago      63.2MB

基于此去建其他的镜像:

建一个文件,名字叫Dockerfile

FROM ubuntu:18.04
MAINTAINER hwy <190998035@qq.com>

ENV DEBIAN_FRONTEND=noninteractive
ENV LANG C.UTF-8

COPY requirements.txt /tmp
WORKDIR /tmp

RUN  sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list && 
     apt-get clean && 
     apt-get update && 
     apt-get install -y libmysqlclient-dev tzdata  
                        python3 python3-dev python3-pip 
    && apt-get clean 
    && apt-get autoclean 
	&& ln -s /usr/bin/pip3 /usr/bin/pip && ln -s /usr/bin/python3 /usr/bin/python 
	
	&& pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple  
	&& rm -rf /var/lib/apt/lists/* && rm /tmp/requirements.txt
	
CMD ["bash"]

requirements.txt里是Python要安装的包,文件和Dockerfile放在同一个目录

xxxx@xxx:/data/docker$ cat requirements.txt 
ansible

执行

docker build -t python3:v1 ./

执行成功可看到新做的镜像

xxxx@xxxx:/data/docker$ docker images 
REPOSITORY        TAG            IMAGE ID       CREATED         SIZE
python3           v1             a632b9b4cb37   3 minutes ago   948MB
ubuntu            18.04          fdf0753c97a9   3 days ago      63.2MB

进入镜像可使用python3和安装的ansible
 

zhaolx@zhaolx:/data/docker$ docker run -it a632b9b4cb37 /bin/bash
root@d090c172d912:/tmp# python
Python 3.6.9 (default, Mar 15 2022, 13:55:28) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
root@d090c172d912:/tmp# ansible --version
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 
2.12. Current version: 3.6.9 (default, Mar 15 2022, 13:55:28) [GCC 8.4.0]. This feature will be removed 
from ansible-core in version 2.12. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
ansible [core 2.11.10] 
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.6.9 (default, Mar 15 2022, 13:55:28) [GCC 8.4.0]
  jinja version = 3.0.3
  libyaml = Tru

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/835545.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号