找回密码
 注册
查看: 4473|回复: 2

运行第一个容器

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2018-2-16 07:12:20 | 显示全部楼层 |阅读模式
环境准备好了,马上运行第一个容器,执行如下命令:5 `' m; K& Q: A% C0 ^4 i8 P
   docker run -d -p 80:80 httpd
8 a+ I/ H9 H% Y2 G6 l
# w9 |1 f4 v) @; |运行结果如下过程:) p/ u4 J$ z1 a2 ^  m+ d+ u
Unable to find image 'httpd:latest' locally
* t" f; z/ v- f( }7 ]0 P. Z$ Dlatest: Pulling from library/httpd7 g" W2 F! k. w8 I; C
4176fe04cefe: Pull complete 8 g; M! P! c  V" u
d6c01cf91b98: Pull complete + {  P: c" h! R6 J
b7066921647a: Pull complete ! ]* v% `6 @; f* q, P- Q9 g# _" }
643378aaba88: Pull complete ! ~( Q2 z1 f% c  P1 Z
3c51f6dc6a3b: Pull complete # W% h! f1 M" p2 |
4f25e420c4cc: Pull complete ! L/ ]- o8 u& f0 ^. K7 [) F# @
ccdbe37da15c: Pull complete 4 A4 c- a$ ^) Y. q
Digest: sha256:5a73586de6429d7ffbf8de990c82a0027c676eb1e438bbe7f9307d2cf285ee37
; l& l6 ]# Z% x! s$ Q7 Q" nStatus: Downloaded newer image for httpd:latest: q6 R0 d" ~2 Y% X
2da567ec704b670b041b1eb0195c0312d29732baee2e6e06b3645d1f28f0f720
/ a" {1 X8 F( @( L* d

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2018-6-21 15:15:42 | 显示全部楼层
报错内容:Failed to get D-Bus connection: Operation not permitted。3 X8 v! A  J3 S9 c+ \

; v7 `; F5 K  @+ w5 u! S/ v3 O报这个错的原因是dbus-daemon没能启动。systemctl并不是不能使用。将CMD或者entrypoint设置为/usr/sbin/init即可。docker容器会自动将dbus等服务启动起来。如下:' ^3 y; b; T$ z4 W) n, @# q! [! h$ g
docker run --privileged -ti --name test  docker.io/centos:7  /usr/sbin/init
( C5 a, ~3 f7 e* ^2 `. m; X. C2 U; ]2 V
# docker run --privileged -ti --name centos7.2 docker.io/centos:7 /usr/sbin/init' M, w, q+ F/ C4 B4 U! F
Unable to find image 'centos:7' locally' j  n, {3 F% Q0 d
7: Pulling from library/centos8 y* a8 O, i/ R  K1 H& K  @
7dc0dca2b151: Pull complete
0 E2 t( |. Z1 g+ H: x7 R" ]3 dDigest: sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa5322
* d# Q- B- ]; K( KStatus: Downloaded newer image for centos:7
! |4 P5 K$ J/ D. [
9 E! c2 H3 \, r& K! d4 ]# 在创建docker容器时添加--privileged8 ?; W$ B1 d' B  C5 O
docker run --privileged  -ti -e "container=docker"  -v /sys/fs/cgroup:/sys/fs/cgroup  centos  /usr/sbin/init
& C" r- `, h3 W* P# w% f$ D- ?

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2018-6-21 15:37:51 | 显示全部楼层
# docker run --privileged -ti  docker.io/centos:7 /usr/sbin/init- P& I# t" _' I6 a$ n9 j6 ^: `
Unable to find image 'centos:7' locally5 R: B1 J( r8 M4 u2 W7 c1 Z2 R
7: Pulling from library/centos/ H. g, Z, f- N' a+ A
7dc0dca2b151: Pull complete 9 o2 R/ |% J* ^' e9 O, q
Digest: sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa5322& R1 [# e8 X/ z; M6 y
Status: Downloaded newer image for centos:7
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 02:18 , Processed in 0.016259 second(s), 23 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表