admin 发表于 2018-2-16 07:12:20

运行第一个容器

环境准备好了,马上运行第一个容器,执行如下命令:
   docker run -d -p 80:80 httpd

运行结果如下过程:
Unable to find image 'httpd:latest' locally
latest: Pulling from library/httpd
4176fe04cefe: Pull complete
d6c01cf91b98: Pull complete
b7066921647a: Pull complete
643378aaba88: Pull complete
3c51f6dc6a3b: Pull complete
4f25e420c4cc: Pull complete
ccdbe37da15c: Pull complete
Digest: sha256:5a73586de6429d7ffbf8de990c82a0027c676eb1e438bbe7f9307d2cf285ee37
Status: Downloaded newer image for httpd:latest
2da567ec704b670b041b1eb0195c0312d29732baee2e6e06b3645d1f28f0f720

admin 发表于 2018-6-21 15:15:42

报错内容:Failed to get D-Bus connection: Operation not permitted。

报这个错的原因是dbus-daemon没能启动。systemctl并不是不能使用。将CMD或者entrypoint设置为/usr/sbin/init即可。docker容器会自动将dbus等服务启动起来。如下:
docker run --privileged -ti --name testdocker.io/centos:7/usr/sbin/init

# docker run --privileged -ti --name centos7.2 docker.io/centos:7 /usr/sbin/init
Unable to find image 'centos:7' locally
7: Pulling from library/centos
7dc0dca2b151: Pull complete
Digest: sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa5322
Status: Downloaded newer image for centos:7

# 在创建docker容器时添加--privileged
docker run --privileged-ti -e "container=docker"-v /sys/fs/cgroup:/sys/fs/cgroupcentos/usr/sbin/init

admin 发表于 2018-6-21 15:37:51

# docker run --privileged -tidocker.io/centos:7 /usr/sbin/init
Unable to find image 'centos:7' locally
7: Pulling from library/centos
7dc0dca2b151: Pull complete
Digest: sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa5322
Status: Downloaded newer image for centos:7
页: [1]
查看完整版本: 运行第一个容器