Docker学习实践 (3)-- 运行第一个容器

了解了Docker 相关基础概念以后,着手运行第一个容器。

基本概念:


(图片来源于“每天5分钟玩转Docker容器技术”)


容器环境:

1、管理工具 - Docker Engine 
2、runtime - runc ,Docker 的默认 runtime
3、操作系统 - Ubuntu 

Docker安装:由于在公共镜像仓库拉取镜像需要https协议,需要对于组件的安装。

1、apt-get install curl
2、apt-get install ca-certificates
3、apt-get install software-properties-common

4、apt-get install  apt-transprt-https 安装不顺利,报错:Unable to locate package apt-transprt-https,需要单独下载安装包及依赖包:

wget http://ftp.nl.debian.org/debian/pool/main/a/apt/apt-transport-https_1.4.8_amd64.deb
dpkg -i apt-transport-https_1.4.8_amd64.deb
wget http://ftp.nl.debian.org/debian/pool/main/a/apt/libapt-pkg5.0_1.4.8_amd64.deb
dpkg -i libapt-pkg5.0_1.4.8_amd64.deb

5、添加 Docker 官方的 GPG key
curl -fssl https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

6、将 Docker 的源添加到 /etc/apt/sources.list
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

7、安装Docker
apt-get install docker-ce

8、运行第一个容器
  docker run -d -p 80:80 httpd

报错:拉取镜像失败,由于连接registry-1.docker.io主站超时,解决方式就配置镜像站点,网络加速

当你下载安装的Docker Version不低于1.10时,建议直接通过daemon config进行配置。
使用配置文件 /etc/docker/daemon.json,没有时新建
{
    "registry-mirrors": ["<your accelerate address>"]
}

重启docker

sudo systemctl daemon-reload
sudo systemctl restart docker

再次运行成功:

docker run -d -p 80:80 httpd

通过ie访问宿主机80端口:

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值