看看是否存在/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



