mac下docker的搭建和使用
2018-03-29 15:02
363 查看
环境说明
操作系统:macOS High SierraDocker 版本:docker
内容摘要:mac下docker的搭建和使用、docker加速器的配置、docker私有仓库的搭建、docker常用命令、docker镜像的定制
Docker 安装
直接访问docker 官网,下载docker CE 版本进行安装https://store.docker.com/editions/community/docker-ce-desktop-mac
docker 默认的本地镜像时存在当前用户目录下的,为了方便管理,将其转移到专用的数据分区中
安装docker-compose
wget https://bootstrap.pypa.io/get-pip.py sudo python get-pip.py sudo pip install six --upgrade --ignore-installed sudo pip install docker-compose
Docker 加速器
配置阿里云加速器访问 https://dev.aliyun.com/search.html 并注册
获取加速地址 https://8q2dp9p9.mirror.aliyuncs.com
cat .docker/daemon.json { "debug" : true, "experimental" : true, "registry-mirrors" : [ "https://8q2dp9p9.mirror.aliyuncs.com" ] }
Docker 私有仓库
为了方便对docker镜像的修改及定制,所以在本地搭建私有仓库docker pull registry docker run -d -p 5000:5000 --restart=always -h registry \ --name registry \ -v /Volumes/MacSoft/data/registry/config/config.yml:/etc/docker/registry/config.yml \ -v /Volumes/MacSoft/data/registry/data:/var/lib/registry \ registry docker exec -it registry sh #进入容器 Ctrl-p Ctrl-q #退出 curl -XGET http://127.0.0.1:5000/v2/_catalog[/code] 本地仓库非安全配置cat .docker/daemon.json { "insecure-registries" : [ "127.0.0.1:5000" ], "debug" : true, "experimental" : true, "registry-mirrors" : [ "https://8q2dp9p9.mirror.aliyuncs.com" ] }
修改 /etc/docker/registry/config.yml 增加delete 选项version: 0.1 log: fields: service: registry storage: delete: enabled: true cache: blobdescriptor: inmemory filesystem: rootdirectory: /var/lib/registry http: addr: :5000 headers: X-Content-Type-Options: [nosniff] health: storagedriver: enabled: true interval: 10s threshold: 3
Ctrl-p Ctrl-q #退出
docker restart registry #重启镜像
增加web管理端
我选用的是Breezes
git clone https://gitee.com/kbsonlong/Breezes.git
修改下Dockerfile
cat DockerfileFROM centos MAINTAINER Mr.tao <staugur@saintic.com> ADD src /Breezes ADD misc/supervisord.conf /etc/supervisord.conf ADD requirements.txt /tmp WORKDIR /Breezes RUN yum -y update RUN yum -y install wget gcc python-devel RUN wget https://bootstrap.pypa.io/get-pip.py RUN python get-pip.py RUN pip install --timeout 30 --index https://pypi.douban.com/simple/ -r /tmp/requirements.txt EXPOSE 10210 ENTRYPOINT ["supervisord"]
构建镜像
docker build -t breezes .
运行镜像
docker run -d -p 10210:10210 --restart=always -h breezes \
--name breezes breezes
保存镜像到私有仓库
docker tag breezes 127.0.0.1:5000/breezes
docker push 127.0.0.1:5000/breezesDocker 常用命令
场景一:镜像下载、运行及删除docker pull hello-world #下载镜像 docker images #查看当前镜像名 docker ps -a #查看当前运行的镜像 docker run hello-world #运行hello-word 镜像 docker ps -a #查看当前运行的镜像信息 docker stop {ID} #停止该镜像 docker rm {ID} #在运行列表中删除镜像 docker rmi {ID} #在本地镜像库中删除镜像
场景二:下载镜像并直接运行docker run --name ubuntu -it ubuntu bash docker cp dd ubuntu:tmp/ #复制文件dd 到容器的/tmp 目录 Ctrl-p Ctrl-q #退出
场景三:修改镜像,并保存到私有仓库
>###### 期望结果:在ubuntu 镜像中添加 apache,将新的镜像保存到私有仓库中docker exec -it ubuntu bash apt-get update apt-get install apache2 Ctrl-p Ctrl-q #退出 docker commit -a "mir355" -m "ubuntu add apache2" {ID} private/ubuntu_apache:v1 #保存镜像 docker stop ubuntu docker rm ubuntu docker run -i -t --name apache2 -p 8080:80 private/ubuntu_apache:v1 /bin/bash /etc/init.d/apache2 start Ctrl-p Ctrl-q #退出 #通过 docker tag重命名镜像,使之与registry匹配 docker tag private/ubuntu_apache:v1 127.0.0.1:5000/private/ubuntu_apache:v1 #保存到私有仓库 docker push 127.0.0.1:5000/private/ubuntu_apache:v1 curl http://127.0.0.1:5000/v2/_catalog #下载镜像 docker pull 127.0.0.1:5000/private/ubuntu_apache:v1
完结
相关文章推荐
- Mac下使用docker搭建STF(踩坑失败)
- 在mac中使用Docker搭建oracle
- mac 下使用Docker安装搭建tensorflow环境
- 在Mac平台使用Docker搭建AOSP(Android源代码)编译环境
- mac 下使用Docker安装搭建tensorflow环境
- mac 下使用Docker安装搭建tensorflow环境
- 在Ubuntu上使用Docker搭建Selenium Grid环境
- 如何使用Docker、Docker-Compose和Rancher搭建部署Pipeline(二)
- 使用Docker搭建elastixsearch服务
- 使用Docker Swarm搭建分布式爬虫集群
- 使用DockerToolbox在MacOSX上安装Docker
- 如何使用docker搭建oracle测试环境
- 使用docker搭建zookeeper集群
- Docker 使用指南 (二)—— 搭建本地仓库
- CentOS6.5使用 Docker 搭建 Java Web 运行环境
- 使用Docker在本地搭建Hadoop分布式集群
- 在centos中使用Docker搭建LNMP环境,附Docker常用方法
- 使用Docker搭建consul集群+registrator实现服务自动注册。
- docker学习(2) mac中docker-machine使用vmware fusion以及配置国内镜像加速