docker save 镜像id > 镜像的压缩文件 #官方文档解释的是,docker save用的是tar命令压缩,应该是没有其他压缩格式的 [root@s25linux ~]# docker save 45d7f887125d > /opt/s25-centos-vim.tar.gz #你可以删掉本地的镜像,然后重新导入该压缩文件,模拟发送给同事的操作
导入镜像
1 2 3 4
比如小李运维同志,他收到了该docker镜像压缩文件,在他的机器上导入该进项 docker load < /opt/s25-centos-vim.tar.gz 首次导入该进项的时候,发现丢失了镜像tag标签,重新赋予一个即可 docker tag 45d7f887125d s25-new-centos-vim
上传镜像
系统登录 docker
docker login
1 2 3 4 5 6 7 8
docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: pythl Password: Login Succeeded
Logging in with your password grants your terminal complete access to your account. For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/
# FROM 指令表示,告诉该dockerfile以哪个镜像为基础 # 比如你的技术老大,要求你们程序运行在ubuntu中 # FROM ubuntu # FROM centos FROM scratch #制作base image 基础镜像,尽量使用官方的image作为base image FROM centos #使用base image FROM ubuntu:14.04 #带有tag的base image
ENV #环境变量,尽可能使用ENV增加可维护性 ENV MYSQL_VERSION 8.0 RUN yum install -y mysql-server=“${MYSQL_VERSION}”
RUN yum install -y mysql-server=“${MYSQL_VERSION}” RUN yum install -y mysql-server=“${MYSQL_VERSION}” RUN yum install -y mysql-server=“${MYSQL_VERSION}” RUN yum install -y mysql-server=“${MYSQL_VERSION}” RUN yum install -y mysql-server=“${MYSQL_VERSION}” RUN yum install -y mysql-server=“${MYSQL_VERSION}”
实战
1.准备好一个 flask 代码文件:s25_flask.py,检查需要哪些依赖步骤
1 2 3 4 5 6 7
from flask import Flask app=Flask(__name__) @app.route('/') defhello(): return"linux就即将结束了,祝大家,找到好工作,有linux问题呢,尽量和我来沟通,互相学习" if __name__=="__main__": app.run(host='0.0.0.0',port=8080)
1.docker提供了一个类似于 github 的仓库dockerhub,网址需要注册使用 2.注册docker id后,在 linux 中登录dockerhub docker login
注意要保证 image 的 tag 是账户名,如果镜像名字不对,需要改一下 tag
docker tag 镜像 dockerhub帐号名/centos-vim
1 2 3 4 5
➜ ~ docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: xxx Password: Login Succeeded
[root@6482683a6a60 /]# yum install -y wget Failed to set locale, defaulting to C.UTF-8 CentOS Linux 8 - AppStream 75 B/s | 38 B 00:00 Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
进入到 yum 的 repos 目录
1
cd /etc/yum.repos.d/
修改 centos 文件内容
1 2
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
生成缓存更新(第一次更新,速度稍微有点慢,耐心等待两分钟左右)
1
yum makecache
运行 yum update 并重新安装 vim
1 2
yum update -y yum -y install vim
debian 设置源
apt-get 下载报错
设置国内源
1
sed -i 's#http://deb.debian.org#https://mirrors.163.com#g' /etc/apt/sources.list
更新源
1
apt-get update
安装软件
1
apt-get install -y vim
ubuntu
apt 下载报错
1 2 3 4 5
root@0ea113202112:/# apt install vim Reading package lists... Done Building dependency tree... Done Reading state information... Done E: Unable to locate package vim
设置国内源
1
sed -i 's#http://deb.debian.org#https://mirrors.163.com#g' /etc/apt/sources.list