Docker- 2、运行第一个容器

容器需要管理工具、runtime 和操作系统,选择如下:
1. 管理工具 - Docker Engine,因为 Docker 最流行使用最广泛。
2. runtime - runc,Docker 的默认 runtime
3. 操作系统 - Ubuntu,虽然存在诸如 CoreOS 的容器 OS,因考虑到我们目前处于初学阶段,选择大家熟悉的操作系统更为合适。等具备了扎实的容器基础知识后再使用容器 OS 会更有利。

创建httpd容器:

[root@syslog ~]# docker run -d -p 80:80 httpd
Unable to find image 'httpd:latest' locally
latest: Pulling from library/httpd
bb79b6b2107f: Pull complete
26694ef5449a: Pull complete
7b85101950dd: Pull complete
da919f2696f2: Pull complete
3ae86ea9f1b9: Pull complete
Digest: sha256:b82fb56847fcbcca9f8f162a3232acb4a302af96b1b2af1c4c3ac45ef0c9b968
Status: Downloaded newer image for httpd:latest
WARNING: IPv4 forwarding is disabled. Networking will not work.
ca151df42a4895a3af89aa34416a936dfa25261b3106e69ce9f054b152b644e4
docker: Error response from daemon: driver failed programming external connectivity on endpoint keen_gauss (ad1a5297ff09fa85f9871529b2a9dc81a6138ea146a2e12bbe82eddcd2f03865):  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 80 -j DNAT --to-destination 172.17.0.2:80 ! -i docker0: iptables: No chain/target/match by that name.
(exit status 1)).

 

错误1:WARNING: IPv4 forwarding is disabled. Networking will not work.
         没有开启转发,配置 /etc/sysctl.conf ,添加 net.ipv4.ip_forward=1
vim /etc/sysctl.conf

#配置转发
net.ipv4.ip_forward=1

#重启服务,让配置生效
systemctl restart network

#查看是否成功,如果返回为“net.ipv4.ip_forward = 1”则表示成功

sysctl net.ipv4.ip_forward

 

错误2:iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 80 -j DNAT --to-destination 172.17.0.2:80 ! -i docker0: iptables: No chain/target/match by that name
解决: https://blog.csdn.net/jabony/article/details/90177831 重启docker : systemctl restart docker
 
 
[root@syslog ~]# docker run -d -p 80:80 httpd
be1927f4573db2668ab8ce6ada794c55593fc6b2ec56ee4fad3e30c923f6f5c1
 
 
过程:
1. 从 Docker Hub 下载 httpd 镜像。镜像中已经安装好了 Apache HTTP Server。
2. 启动 httpd 容器,并将容器的 80 端口映射到 host 的 80 端口。
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值