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

运行第一个容器

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2018-2-16 07:12:20 | 显示全部楼层 |阅读模式
环境准备好了,马上运行第一个容器,执行如下命令:
+ T/ E2 o4 r6 G' r7 @   docker run -d -p 80:80 httpd
8 b) l6 d% y$ X* v) X+ j2 }' T* V  `1 A7 [: \2 A" o
运行结果如下过程:6 {( B5 t! Z+ {
Unable to find image 'httpd:latest' locally* R" _$ x: [" q8 ~' E7 D! z
latest: Pulling from library/httpd' f1 r/ C: |7 X! f5 U
4176fe04cefe: Pull complete
" _7 p9 ]9 e2 e% Y8 ^8 ?d6c01cf91b98: Pull complete
! y8 B8 j; v: @/ x9 u0 Yb7066921647a: Pull complete 0 |+ z8 C: Y6 z2 G
643378aaba88: Pull complete
: c0 [. l: O+ r5 D$ W3c51f6dc6a3b: Pull complete $ K0 I: I, y8 f
4f25e420c4cc: Pull complete
+ P9 f! ^% h" r2 O5 qccdbe37da15c: Pull complete
, r& G1 [% r: A% _- L+ ]3 pDigest: sha256:5a73586de6429d7ffbf8de990c82a0027c676eb1e438bbe7f9307d2cf285ee37
3 h; f" B+ E; ZStatus: Downloaded newer image for httpd:latest
. Y6 X! X' J1 V# _! f0 d2da567ec704b670b041b1eb0195c0312d29732baee2e6e06b3645d1f28f0f720' n  ~9 U( \- h1 N; q( q$ W0 i! B- D

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2018-6-21 15:15:42 | 显示全部楼层
报错内容:Failed to get D-Bus connection: Operation not permitted。2 Z7 j$ d7 p4 O+ C- S0 e4 M' g
* ^! F5 Y, X1 u4 i" J, a
报这个错的原因是dbus-daemon没能启动。systemctl并不是不能使用。将CMD或者entrypoint设置为/usr/sbin/init即可。docker容器会自动将dbus等服务启动起来。如下:8 h$ ]6 N9 o2 ]) [0 P5 ^6 ]* w
docker run --privileged -ti --name test  docker.io/centos:7  /usr/sbin/init
$ R4 D( r5 G9 k' x
* M; Z0 ?% W; y% ^$ ]# docker run --privileged -ti --name centos7.2 docker.io/centos:7 /usr/sbin/init, P1 }& x: K: m& H
Unable to find image 'centos:7' locally
1 k, a: f; N; |0 ]7: Pulling from library/centos
- g/ c5 {# M* i4 S- Z  y! z7dc0dca2b151: Pull complete
4 A1 s# k9 A7 G' O% DDigest: sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa53226 }9 p, }* T: E4 @9 h* G
Status: Downloaded newer image for centos:71 S; F, p& A1 |7 R+ A
+ e  K: ?2 ~( F! ?& R% y
# 在创建docker容器时添加--privileged
. y$ ?) i5 a( ^docker run --privileged  -ti -e "container=docker"  -v /sys/fs/cgroup:/sys/fs/cgroup  centos  /usr/sbin/init  q8 c! i1 A! [& k- H/ t" s( K

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2018-6-21 15:37:51 | 显示全部楼层
# docker run --privileged -ti  docker.io/centos:7 /usr/sbin/init
7 }7 o7 p) y2 K7 m+ yUnable to find image 'centos:7' locally
. O( k, y: v: p7: Pulling from library/centos" c, n: \4 R. R! q+ l- H
7dc0dca2b151: Pull complete
0 D/ V, {$ \' mDigest: sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa5322
7 n9 s" e- J. O! L, zStatus: Downloaded newer image for centos:7
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-12 00:26 , Processed in 0.022551 second(s), 23 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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