centos7安装docker及私有仓库,centos7docker仓库


1.初始化网络


安装centos7后使用yum提示域名无法解析.查看本地网络,ifconfig不可用,centos7中用ip命令代理了ifconfig.


ip addr, 显示只有本地回环地址。


cd /etc/sysconfig/network-scripts, 查看


网卡名对应的文件


onboot为no


改为yes,重启centos后,网络已联通


2.uname -r检查内核


3.yum update


4.添加yum源


sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'


[dockerrepo]


name=Docker Repository


baseurl=https://yum.dockerproject.org/repo/main/centos/7/


enabled=1


gpgcheck=1


gpgkey=https://yum.dockerproject.org/gpg


EOF


5.安装


yum install docker-engine


6.开启docker守护进程


$ sudo service docker start


查看


ps -ef | grep dockerd


7.检查docker是否安装成功


docker run hello-world


提示如下内容表示安装成功


Unable to find image 'hello-world:latest' locally


latest: Pulling from library/hello-world


c04b14da8d14: Pull complete


Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9


Status: Downloaded newer image for hello-world:latest


Hello from Docker!


This message shows that your installation appears to be working correctly.


To generate this message, Docker took the following steps:


1. The Docker client contacted the Docker daemon.


2. The Docker daemon pulled the "hello-world" image from the Docker Hub.


3. The Docker daemon created a new container from that image which runs the


executable that produces the output you are currently reading.


4. The Docker daemon streamed that output to the Docker client, which sent it


to your terminal.


To try something more ambitious, you can run an Ubuntu container with:


$ docker run -it ubuntu bash


Share images, automate workflows, and more with a free Docker Hub account:


https://hub.docker.com


For more examples and ideas, visit:


https://docs.docker.com/engine/userguide/


8.添加到开机启动项


chkconfig docker on


9.创建docker私服


docker run -p 5000:5000 registry


测试:


下载镜像


docker pull ubuntu:12.04


运行容器


docker run -i -t ubuntu:12.04 /bin/bash


修改文件内容


root@ae00895eb68e:cd /home


echo "print 'test'" > t1.py


exit


提交到本地


docker commit -m "add t1.py" -a "lyc" ae00895eb68e ubuntu:12.04


将镜像做tag


docker tag img_id 127.0.0.1:5000/ubuntu


提交到私有仓库


docker push 127.0.0.1:5000/ubuntu


删除本地镜像


docker rmi --force img_id


从私有仓库下载


docker pull 127.0.0.1:5000/ubuntu


运行容器


docker run -i -t 127.0.0.1:5000/ubuntu


查看文件存在

导出镜像到文件Dockersave -o [file_name] [img_id]|[repos_name]


导入文件到镜像 docker load --input [img_file]

他们之间的关系如下图所示:

常用命令


运行容器 docker run -i -t ubuntu:12.04 /bin/bash


列出本地镜像 docker images


显示本机的所有容器 docker ps -a


显示正在运行的容器 docker ps


搜索镜像 docker searchMySQL


删除镜像 docker rmi --force img_id


导出镜像到文件 docker save -o [file_name] [img_id]|[repos_name]


导入文件到镜像 docker load --input [img_file]


查看指定容器的日志 docker logs [container_id] 或 docker logs -f [container_id]


停止容器 docker stop [container_id]


启动一个停止的容器 docker start [container_id]


重启容器 docker restart [container_id]


容器导出 docker export [container_id] > ubuntu.tar.gz


删除容器 docker rm -f [container_id]


导入容器快照到镜像 cat ubuntu.tar.gz | sudo docker import - [repos_name]


查看容器内的进程 docker top [container_id]


查看容器详细信息 docker inspect [container_id]

相关内容

    暂无相关文章