centos7安装docker及私有仓库

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

查看文件存在


导出镜像到文件 docker save -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 search mysql
删除镜像 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]


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值