WARNING: No blkio throttle.read_bps_device support WARNING: No blkio throttle.write_bps_device support WARNING: No blkio throttle.read_iops_device support WARNING: No blkio throttle.write_iops_device support
docker镜像的使用
查找注册仓库中的镜像
1
docker search <镜像>
1 2 3 4 5 6 7
root@Executor:/home/docker# docker search httpd NAME DESCRIPTION STARS OFFICIAL AUTOMATED httpd The Apache HTTP Server Project 4090 [OK] centos/httpd-24-centos7 Platform for running Apache httpd 2.4 or bui… 44 centos/httpd 35 [OK] clearlinux/httpd httpd HyperText Transfer Protocol (HTTP) ser… 2 ...
其中STARS表明该镜像的权威性
OFFICIAL表明该镜像是否为官方镜像
从仓库拉取镜像
要私人定制一个花里胡哨的ubuntu镜像,首先得有一个干净的基础镜像
1
docker pull <仓库名>:<标签>
这里仓库名一般就是操作系统名比如ubuntu,标签就是操作系统版本比如20.04
因为docker仓库一般以操作系统命名,其中的镜像文件一般以对应操作系统版本号命名
1 2 3 4 5 6
root@Executor:~# docker pull ubuntu:20.04 20.04: Pulling from library/ubuntu d7bfe07ed847: Pull complete Digest: sha256:fd92c36d3cb9b1d027c4d2a72c6bf0125da82425fc2ca37c414d4f010180dc19 Status: Downloaded newer image for ubuntu:20.04 docker.io/library/ubuntu:20.04
查看本地镜像列表
1 2 3 4
root@Executor:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 20.04 20fffa419e3a 6 weeks ago 72.8MB ansible/ubuntu14.04-ansible latest 4621d4fe2959 6 years ago 461MB
栏目
意义
RESPOSITORY
镜像仓库源
TAG
镜像标签
IMAGE ID
镜像ID
CREATED
镜像创建时间
SIZE
镜像大小
可以使用仓库源:镜像标签来指定一个唯一的镜像,也可以直接使用镜像ID指定一个唯一的镜像
删除本地镜像
1
docker rmi <镜像>
这里镜像或者是仓库原:镜像标签指定,或者是镜像ID指定
甚至不用输全信息就可以指定唯一一个镜像
比如只输入镜像ID的前两位或者前三位
1 2 3 4 5 6 7 8 9 10
root@Executor:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 20.04 20fffa419e3a 6 weeks ago 72.8MB ubuntu 18.04 5a214d77f5d7 9 months ago 63.1MB ansible/ubuntu14.04-ansible latest 4621d4fe2959 6 years ago 461MB root@Executor:~# docker rmi 5a Untagged: ubuntu:18.04 Untagged: ubuntu@sha256:0fedbd5bd9fb72089c7bbca476949e10593cebed9b1fb9edf5b79dbbacddd7d6 Deleted: sha256:5a214d77f5d747e6ed81632310baa6190301feeb875cf6bf9da560108fa09972 Deleted: sha256:824bf068fd3dc3ad967022f187d85250eb052f61fe158486b2df4e002f6f984e
root@Executor:/home/docker# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ssh/ubuntu latest 886ba4c00ba4 27 seconds ago 235MB ubuntu 20.04 20fffa419e3a 6 weeks ago 72.8MB
root@Executor:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 49e5c3d8f7c6 ubuntu:20.04 "bash" About an hour ago Up 9 minutes lucid_ramanujan root@Executor:~# docker exec -it 49 bash root@49e5c3d8f7c6:/# exit exit root@Executor:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 49e5c3d8f7c6 ubuntu:20.04 "bash" About an hour ago Up 9 minutes lucid_ramanujan
退出容器使用exit,或者ctrl+d
导出/导入容器
将容器导出成tar包
1
docker export <容器> > <位置>
比如将49e5c3d8f7c6这个容器(已安装ssh)导出到当前目录
1 2 3
root@Executor:/home/docker# docker export 49 > ssh-ubuntu.tar root@Executor:/home/docker# ls ssh-ubuntu.tar
将tar包导入成镜像(不能直接导入成容器)
1
docker import [OPTIONS] <tar包> <镜像>
将tar包导入为指定名称的镜像
1 2 3 4 5 6 7 8
root@Executor:/home/docker# ls ssh-ubuntu.tar root@Executor:/home/docker# docker import ssh-ubuntu.tar ssh/ubuntu sha256:725bf542d42fc0f7aad48f47ef2b81d1bcf7931bd1283a2b91ccbd3f8246e876 root@Executor:/home/docker# docker images REPOSITORY TAG IMAGE ID CREATED SIZE ssh/ubuntu latest 725bf542d42f 5 seconds ago 234MB ubuntu 20.04 20fffa419e3a 6 weeks ago 72.8MB
root@Executor:~# docker network ls NETWORK ID NAME DRIVER SCOPE 3ce19195196f bridge bridge local c1341214f1d0 host host local d4e52924ce6b none null local
cat > /etc/apt/sources.list << EOF deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib deb http://mirrors.aliyun.com/debian-security stretch/updates main deb-src http://mirrors.aliyun.com/debian-security stretch/updates main deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib EOF
docker run -dit -p 10011:80 apache/ubuntu:latest /bin/bash -c "/start.sh"
-d后台运行
-it启动交互终端
-p 10011:80,wsl的10011端口映射到容器的80端口
apache/ubuntu:latest我们自定义的镜像名
/bin/bash -c "/start.sh"命令行参数,启动后立刻自动执行
没有指定网络模式默认为桥接模式
没有指定端口上的传输层服务类型默认为TCP服务
1 2 3 4 5
root@Executor:~# docker run -dit -p 10011:80 apache/ubuntu /bin/bash -c "/start.sh" edc1b61f6c7a20ce4d85989ffa4c5042dc13769161f4d89952604a8496b869d1 root@Executor:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES edc1b61f6c7a apache/ubuntu "docker-php-entrypoi…" 2 seconds ago Up 1 second 0.0.0.0:10011->80/tcp, :::10011->80/tcp friendly_northcutt
root@Executor:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES edc1b61f6c7a apache/ubuntu "docker-php-entrypoi…" 12 minutes ago Up 11 minutes 0.0.0.0:10011->80/tcp, :::10011->80/tcp friendly_northcutt
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse