docker—tomcat 报错:Failed to get D-Bus connection: Operation not permitted
docker search centos 查系统镜像
docker pull docker.io/centos
进入容器
[root@git opt]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/tomcat8 latest 37e6b19c14e0 25 hours ago 517 MB gitalb-zh latest dd61a1ec3cdc 2 days ago 1.72 GB docker.io/twang2218/gitlab-ce-zh latest 1f71f185271a 11 days ago 1.63 GB docker.io/centos latest 2d194b392dd1 2 weeks ago 195 MB
docker run -it docker.io/centos /bin/bash
安装tomcat
yum -y install tomcat...... 代码路径: /usr/share/tomcat/webapps/ROOT/index.jsp 配置文件路径: /usr/share/tomcat/
把装好tomcat容器,生成镜像
[root@git opt]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a9717660d785 docker.io/tomcat8 "/usr/sbin/init" About an hour ago Up About an hour 0.0.0.0:888->8080/tcp tomcat8 [root@git opt]# docker commit a9717660d785 docker.io/tomcat8
用新镜像生成容器进行访问
[root@git opt]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/tomcat8 latest 37e6b19c14e0 26 hours ago 517 MB gitalb-zh latest dd61a1ec3cdc 2 days ago 1.72 GB docker.io/twang2218/gitlab-ce-zh latest 1f71f185271a 11 days ago 1.63 GB docker.io/centos latest 2d194b392dd1 2 weeks ago 195 MB
docker run -itd -p 888:8080 --privileged=true --name tomcat8 docker.io/tomcat8 /usr/sbin/init (注:参数-d 是后台运行) 结尾如果 /bin/bash 进入容器后无法启动服务,报错:Failed to get D-Bus connection: Operation not permitted 据说是centos7的BUG 所以这里需 /usr/sbin/init 进入容器后可以使用systemctl 命令 因为这样会把宿主机的dbus服务带入容器启动 [root@a9717660d785 /]# ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 07:38 ? 00:00:00 /usr/sbin/init root 17 1 0 07:38 ? 00:00:00 /usr/lib/systemd/systemd-journald root 27 1 0 07:38 ? 00:00:00 /usr/sbin/sshd -D dbus 28 1 0 07:38 ? 00:00:00 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation root 29 1 0 07:38 ? 00:00:00 /usr/lib/systemd/systemd-logind
如果想进入:
[root@git opt]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a9717660d785 docker.io/tomcat8 "/usr/sbin/init" About an hour ago Up About an hour 0.0.0.0:888->8080/tcp tomcat8 [root@git opt]# docker exec -it a9717660d785 bash
访问看效果: