不管是Mac仍是Windows都须要先安装Docker Toolbox,这样能够更加便于你对docker的管理: Mac系统的安装文件目录: mirrors.aliyun.com/docker-toolbox/mac Windows系统的安装文件目录: mirrors.aliyun.com/docker-toolbox/windows
docker-machine create --engine-registry-mirror=https://*******(阿里为会你提供).mirror.aliyuncs.com -d virtualbox default
docker-machine env default eval "$(docker-machine env default)" (win下使用docker-machine env default | Invoke-Expression) docker info
使用命令去阿里云镜像下载docker引擎 curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh -
您可使用以下的脚本将mirror的配置添加到docker daemon的启动参数中(12.04和14.04) echo "DOCKER_OPTS=\"\$DOCKER_OPTS --registry-mirror=https://ie68a4mu.mirror.aliyuncs.com\"" | sudo tee -a /etc/default/docker sudo service docker restart
安装源 $ sudo apt-get install apt-transport-https ca-certificates 添加gpg秘钥 $ sudo apt-key adv --keyserver hk70ADBF76221572C******(阿里为提供) 获取当前系统代号 $ lsb_release -c Codename: trusty 打开/etc/apt/sources.list.d/docker.list加入deb [arch=amd64] http://mirrors.aliyun.com/docker-engine/apt/repo ubuntu-trusty main 这个是阿里的镜像源
apt-get install apparmor 若是你用的不是root用户须要创建一个docker用户组来为那些人受权。
docker search 镜像名 #在镜像仓库中搜索某一类镜像 docker pull 镜像名 #从仓库中将某一镜像下载下来 docker images #查看全部镜像 docker run -it 镜像名:标签名 /bin/bash #实例化运行某一镜像虚拟到容器 docker ps -a #查看全部容器(不加-a是查看正在运行的容器) docker build -t="镜像名:标签名" . #在当前文件夹下寻找Dockerfile文件,按照其内容打包镜像 docker commit -m "提该次交的描述" -a "提交人" 容器名或ID 镜像名:标签名 #将一个容器转化为一个镜像(有依赖关系)(一个镜像最多不能超过127层) docker rm 容器名或ID #删除某容器(所有清除docker rm $(docker ps -a -q)) docker rmi 镜像名或ID #删除某镜像(删除以前确保改镜像没有依赖) docker save -o 镜像包名.tar 镜像名:标签名 #将镜像打包成压缩文件 docker load --input 镜像包.tar #从镜像包里面加载镜像 docker start 容器名或ID #开启某容器 docker stop 容器名或ID #关闭某容器 docker restart 容器名或ID #重启某容器 docker attach 容器名或ID #进入某一正在运行中的容器 docker login #登陆到dockerhub仓库 docker push 镜像名:标签名 #将该镜像上传到仓库中 docker tag 镜像名或ID 新镜像名:标签名 #将该镜像更名 docker logs 容器名或ID #打印容器日志 docker import 容器快照 #导入一个容器快照到本地镜像库
基本语法 使用#来注释 FROM代表要使用那个镜像做为基础镜像 FROM 镜像名:标签 维护这信息 MAINTAINER 维护者名字 RUN命令表示建立镜像是会运行的命令,好比安装应用 RUN apt-get -qq update RUN apt-get -y install vim 除了这些还可使用ADD命令复制本地文件到镜像 ADD my.conf /var/www 使用EXPOSE命令来向外部开放端口 EXPOSE 80 用CMD命令来描述容器启动后运行的程序 CMD ["/usr/sbin/apachectl","-D","FOREGROUND"]
当使用docker run建立容器时,docker后台运行的标准操做: 检查本地是否存在指定镜像,若是不存在先从公有仓库下载 利益镜像建立并启动一个容器 分配一个文件系统,并在只读的镜像层外面褂子一层可读写层 从宿主主机配置的网桥接口中桥接一个虚拟接口到容器中去 从地址池配置一个ip地址给容器 执行用户指定的应用程序 执行完毕后容器被终止
-a, --attach=[] # 指定标准输入输出内容类型,可选 STDIN/STDOUT/STDERR 三项 --add-host=[] Add a custom host-to-IP mapping (host:ip) --blkio-weight=0 Block IO (relative weight), between 10 and 1000 -c, --cpu-shares=0 CPU shares (relative weight) --cap-add=[] Add Linux capabilities --cap-drop=[] Drop Linux capabilities --cgroup-parent= Optional parent cgroup for the container --cidfile= Write the container ID to the file --cpu-period=0 Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota=0 Limit the CPU CFS quota --cpuset-cpus= # 绑定容器到指定CPU运行 --cpuset-mems= # 绑定容器到指定MEM运行 -d, --detach=false # 后台运行容器,并返回容器ID --device=[] Add a host device to the container --dns=[] # 指定容器使用的DNS服务器,默认和宿主一致 --dns-search=[] # 指定容器DNS搜索域名,默认和宿主一致 -e, --env=[] # 设置环境变量 --entrypoint= Overwrite the default ENTRYPOINT of the image --env-file=[] # 从指定文件读入环境变量 --expose=[] Expose a port or a range of ports -h, --hostname= # 指定容器的hostname --help=false Print usage -i, --interactive=false # 以交互模式运行容器,一般与 -t 同时使用 --ipc= IPC namespace to use -l, --label=[] Set meta data on a container --label-file=[] Read in a line delimited file of labels --link=[] Add link to another container --log-driver= Logging driver for container --log-opt=[] Log driver options --lxc-conf=[] Add custom lxc options -m, --memory= Memory limit --mac-address= Container MAC address (e.g. 92:d0:c6:0a:29:33) --memory-swap= Total memory (memory + swap), '-1' to disable swap --name= # 为容器指定一个名称 --net=bridge # 指定容器的网络链接类型,支持 bridge/host/none/container:<name|id> 四种类型 --oom-kill-disable=false Disable OOM Killer -P, --publish-all=false Publish all exposed ports to random ports -p, --publish=[] Publish a container's port(s) to the host --pid= PID namespace to use --privileged=false Give extended privileges to this container --read-only=false Mount the container's root filesystem as read only --restart=no Restart policy to apply when a container exits --rm=false Automatically remove the container when it exits --security-opt=[] Security Options --sig-proxy=true Proxy received signals to the process -t, --tty=false # 为容器从新分配一个伪输入终端,一般与 -i 同时使用 -u, --user= Username or UID (format: <name|uid>[:<group|gid>]) --ulimit=[] Ulimit options --uts= UTS namespace to use -v, --volume=[] Bind mount a volume --volumes-from=[] Mount volumes from the specified container(s) -w, --workdir= Working directory inside the container
在一台有docker的机器上布置仓库,仓库做为容器存在。 $ sudo docker run -d -p 5000:5000 registry 这个时候须要给要上传仓库的镜像包更名字 $ docker tag 镜像名或ID 仓库IP:仓库端口号/镜像名:标签名 而后将docker镜像上传到仓库 $ docker push 仓库IP:仓库端口号/镜像名:标签名 在拉镜像的时候可能会遇到server gave HTTP response to HTTPS client 这个时候在/etc/docker/daemon.json文件中加入{"insecure-registries":["IP地址:端口号"]}
文章来自个人我的博客,欢迎转载:Docker的安装与经常使用命令docker