0.11.1版本docker安装与使用

简介:

关于什么是docker,请参考http://baike.baidu.com/view/11854949.htm?fr=aladdin

我的服务器是ubuntu server 12.04,硬件是dell R420

一、安装

1、安装源

1
2
3
apt-keyadv --keyserver hkp: //keyserver .ubuntu.com:80 --recv-keys36A1D7869245C8950F966E92D8576A8BA88D21E9
sh -c "echo deb https://get.docker.io/ubuntu docker main>/etc/apt/sources.list.d/docker.list"
apt-getupdate

2、安装docker

1
apt-get  install  lxc-docker

3、下载tar包并加入镜像里

一般下载镜像的时候,都是先docker search image_name,然后docker pullimage_name

但由于最近GFW屏蔽了网络,在现在的时候会出现以下错误,根本pull不了镜像。

1
2
Pullingrepository centos
2014 /05/19  13:35:11 Gethttps: //cdn-registry-1 .docker.io /v1/repositories/library/centos/tags read  tcp162.159.253.251:443: connection timed out

所以为了解决此问题,我就从别的地方下载了打包好的tar(后边会解释然后自己打包的),然后使用docker load导入

先下载(有centos与ubuntu)

1
2
wget http: //docker .widuu.com /centos . tar
wget http: //docker .widuu.com /ubuntu . tar

加入到镜像里

1
2
docker load -i centos. tar
docker load -i ubuntu. tar

查看镜像列表

1
2
3
4
5
6
root@ip-10-10-25-218:~ /docker/images #docker load -i centos.tar
root@ip-10-10-25-218:~ /docker/images #docker load -i ubuntu.tar
root@ip-10-10-25-218:~ /docker/images #docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>              <none>              607347d2a946        3 months ago        300.2 MB
ubuntu /widuu        latest             963b9d0e10ba        3 monthsago        155 MB

给centos的改个名

1
2
3
4
5
root@ip-10-10-25-218:~ /docker/images #docker tag 607 centos:latest
root@ip-10-10-25-218:~ /docker/images #docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              607347d2a946        3 months ago        300.2 MB
ubuntu /widuu        latest             963b9d0e10ba        3 monthsago        155 MB

测试镜像是否可用

1
2
3
4
5
6
7
8
9
root@ip-10-10-25-218:~ /docker/images #docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos              latest              607347d2a946        3 months ago        300.2 MB
ubuntu /widuu         latest              963b9d0e10ba        3 months ago        155 MB
root@ip-10-10-25-218:~ /docker/images #docker run centos /bin/echo "hello,i'm centos system"
hello,i'mcentos system
root@ip-10-10-25-218:~ /docker/images #docker run ubuntu/widuu /bin/echo "hello,i'm ubuntu system"
hello,i'mubuntu system
root@ip-10-10-25-218:~ /docker/images #

使用交换模式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
bash -4.1 #root@ip-10-10-25-218:~/docker/exercise/node# docker run -i -t centos /bin/bash
bash -4.1 #ifconfig
eth0      Link encap:Ethernet  HWaddr BA:08:86:7F:F8:48 
           inet addr:172.17.0.6  Bcast:0.0.0.0 Mask:255.255.0.0
           inet6 addr: fe80::b808:86ff:fe7f:f848 /64Scope :Link
           UP BROADCAST RUNNING  MTU:1500 Metric:1
           RX packets:6 errors:0 dropped:2overruns:0 frame:0
           TX packets:2 errors:0 dropped:0overruns:0 carrier:0
           collisions:0 txqueuelen:1000
           RX bytes:488 (488.0 b)  TX bytes:168 (168.0 b)
  
lo        Link encap:Local Loopback 
           inet addr:127.0.0.1  Mask:255.0.0.0
           inet6 addr: ::1 /128  Scope:Host
           UP LOOPBACK RUNNING  MTU:1500 Metric:1
           RX packets:0 errors:0 dropped:0overruns:0 frame:0
           TX packets:0 errors:0 dropped:0overruns:0 carrier:0
           collisions:0 txqueuelen:0
           RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
  
bash -4.1 # exit

退出有2中一种是完全退出,使用exit,另外一中是不完全退出,使用ctrl-p与ctrl-q

这样你推人退出了,但容器状态还是存在。

可用使用docker attach CONTAINER ID来重新进入

二、私有库

由于GFW,所以玩docker没办法pullpush,并且为了安全考虑,为了解决就搭建了私有库。

1
2
3
4
5
6
7
8
9
10
git clonehttps: //github .com /dotcloud/docker-registry .git
cddocker-registry
cd  config
cpconfig_sample.yml config.yml
cd  ..
apt-getinstall python-pip gunicorn build-essential python-dev libevent-dev
 
python-pipliblzma-dev -y
pipinstall -r requirements.txt
gunicorn-k gevent --max-requests 100 --graceful-timeout 3600 -t 3600 -b localhost:5000-w 8 -D  --access-logfile  /tmp/gunicorn .log  docker_registry.wsgi:application

客户端推送镜像到私有库

1、  先注册账号

1
docker login localhost:5000

依次输入你的账号、密码、email

2、给提交的镜像打标签

1
2
3
4
5
6
root@ip-10-10-25-218:~ /docker/exercise/node #docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos-init         latest              5abf7cce3767        3 minutes ago       1.034 GB
centos              latest              607347d2a946        3 months ago        300.2 MB
ubuntu /widuu         latest              963b9d0e10ba        3 months ago        155 MB
root@ip-10-10-25-218:~ /docker/exercise/node # docker tag5abf7cce3767 localhost:5000/centos-init

3、推送到私有库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@ip-10-10-25-218:~ /docker/exercise/node #docker push localhost:5000/centos-init
The pushrefers to a repository [localhost:5000 /centos-init ] (len: 1)
Sendingimage list
Pushingrepository localhost:5000 /centos-init  (1 tags)
Image384630bcda7c already pushed, skipping
Image607347d2a946 already pushed, skipping
5abf7cce3767:Image successfully pushed
Pushingtag  for  rev [5abf7cce3767] on{http: //localhost :5000 /v1/repositories/centos-init/tags/latest }
root@ip-10-10-25-218:~ /docker/exercise/node #docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos-init                  latest              5abf7cce3767        6 minutes ago       1.034 GB
localhost:5000 /centos-init    latest              5abf7cce3767        6 minutes ago       1.034 GB
centos                       latest              607347d2a946        3 months ago        300.2 MB
ubuntu /widuu                 latest             963b9d0e10ba        3 monthsago        155 MB

三、自制镜像

参考http://docs.docker.io/articles/baseimages/

我是在ubuntu系统,所以使用https://github.com/dotcloud/docker/blob/master/contrib/mkimage-rinse.sh

由于使用rinse创建,所以需要安装

1
apt-get  install  rinse

安装centos 5系统

1
bash  mkimage-rinse.sh denglei /centos  centos-5

安装centos 6系统

检测

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@ip-10-10-25-218: /tmp #docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
denglei /centos                6.5                 18eb9205a927        2 minutes ago       127.2 MB
denglei /centos                5.10                2b76af55f4cc        5 minutes ago       81.08 MB
centos-test2                 latest              21639e6b708a        About an hour ago   356.7 MB
ubuntu- test                   latest              a95d7aa1d991        39 hours ago        161.8 MB
centos- test                   latest              28870be2e716        39 hours ago        356.7 MB
centos-omsa                  latest              d3c15db5624e        39 hours ago        1.048 GB
centos-init                  latest              58ef41091c2b        11 days ago         1.055 GB
localhost:5000 /centos-init    latest              5abf7cce3767        11 days ago         1.034 GB
centos                       latest              607347d2a946        4 months ago        300.2 MB
ubuntu /widuu                 latest             963b9d0e10ba        4 monthsago        155 MB
  
root@ip-10-10-25-218: /tmp #docker run denglei/centos:5.10 /bin/echo "hello,i'm centos 5.10system"
hello,i'mcentos 5.10 system
root@ip-10-10-25-218: /tmp #docker run denglei/centos:6.5 /bin/echo "hello,i'm centos 6.5 system"
hello,i'm centos 6.5 system

docker里centos无法ssh的问题

需要关闭pam

1
sed  -i  "s/UsePAM.*/UsePAMno/g"  /etc/ssh/sshd_config

重启ssh服务

1
/etc/init .d /sshd  restart

同时别忘记设置密码



 本文转自 reinxu 51CTO博客,原文链接:http://blog.51cto.com/dl528888/1427150,如需转载请自行联系原作者




相关文章
|
13天前
|
Linux 虚拟化 Docker
win11怎么安装docker的必要设置自学软硬件工程师778天
win11怎么安装docker的必要设置自学软硬件工程师778天
win11怎么安装docker的必要设置自学软硬件工程师778天
|
14天前
|
Ubuntu 关系型数据库 MySQL
在Ubuntu系统的Docker上安装MySQL的方法
以上的步骤就是在Ubuntu系统的Docker上安装MySQL的详细方法,希望对你有所帮助!
85 12
|
26天前
|
Ubuntu 关系型数据库 MySQL
容器技术实践:在Ubuntu上使用Docker安装MySQL的步骤。
通过以上的操作,你已经步入了Docker和MySQL的世界,享受了容器技术给你带来的便利。这个旅程中你可能会遇到各种挑战,但是只要你沿着我们划定的路线行进,你就一定可以达到目的地。这就是Ubuntu、Docker和MySQL的灵魂所在,它们为你开辟了一条通往新探索的道路,带你亲身感受到了技术的力量。欢迎在Ubuntu的广阔大海中探索,用Docker技术引领你的航行,随时准备感受新技术带来的震撼和乐趣。
85 16
|
1月前
|
监控 关系型数据库 MySQL
zabbix7.0.9安装-以宝塔安装形式-非docker容器安装方法-系统采用AlmaLinux9系统-最佳匹配操作系统提供稳定运行环境-安装教程完整版本-优雅草卓伊凡
zabbix7.0.9安装-以宝塔安装形式-非docker容器安装方法-系统采用AlmaLinux9系统-最佳匹配操作系统提供稳定运行环境-安装教程完整版本-优雅草卓伊凡
131 30
|
1月前
|
存储 虚拟化 Docker
Docker Desktop 4.38 安装与配置全流程指南(Windows平台)
Docker Desktop 是容器化应用开发与部署的一体化工具,支持本地创建、管理和运行 Docker 容器。4.38 版本新增 GPU 加速、WSL 2 性能优化和 Kubernetes 1.28 集群管理功能,适用于微服务开发和 CI/CD 流水线搭建。安装要求为 Windows 10 2004 及以上(64 位),需启用 Hyper-V 或 WSL 2。硬件最低配置为 4GB 内存、20GB 存储和虚拟化技术支持的 CPU。安装步骤包括启用系统功能、下载并运行安装程序,完成后配置镜像加速并验证功能。常见问题涵盖 WSL 2 安装不完整、磁盘空间清理及容器外网访问等。
2619 13
|
13天前
|
前端开发 Linux Docker
docker的安装使用0废话版本自学软硬件工程师778天
win11怎么安装docker的必要设置自学软硬件工程师778天
|
21天前
|
存储 SQL 关系型数据库
docker部署n9e开源版本7.4.0
n9e开源版本7.4.0
39 0
|
1月前
|
Ubuntu Linux Docker
Docker 入门全攻略:安装、操作与常用命令指南
Docker 的世界非常广阔,这只是一个开始,请继续探索和学习 Docker 的高级特性和最佳实践。后续也会继续更新相关的理论与实践内容。 只有锻炼思维才能可持续地解决问题,只有思维才是真正值得学习和分享的核心要素。如果这篇博客能给您带来一点帮助,麻烦您点个赞支持一下,还可以收藏起来以备不时之需,有疑问和错误欢迎在评论区指出~
|
1月前
|
Ubuntu Linux Docker
如何在Ubuntu 20.04系统中安装Docker
安装 Docker 引擎的步骤如下:首先更新系统包索引 (`sudo apt update`),安装必要依赖包 (`apt-transport-https` 等),添加 Docker 官方 GPG 密钥及 APT 仓库。接着再次更新包索引并安装 Docker 引擎及相关工具 (`docker-ce` 等)。最后启动 Docker 服务并设置开机自启,通过 `docker --version` 和运行测试容器 (`sudo docker run hello-world`) 验证安装是否成功。
337 0
|
存储 运维 安全
Docker 发布第一个正式版本 1.0
2013年3月20日,我们发布了 Docker 的首个版本。15个月后,我们收获颇丰:既有来自超过 460 位贡献者的 8741 条提交、两百七十五万次下载、超过一万四千个 Docker 化的应用,也有超过一万名用户反馈他们使用 Docker 的经历,从在单台笔记本上运行单个容器,到在云中使用数千个容器进行生产,不一而足。
277 0
Docker 发布第一个正式版本 1.0