docker search centos 查系統鏡像git
docker pull docker.io/centosweb
進入容器docker
[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
安裝tomcatcentos
yum -y install tomcat...... 代碼路徑: /usr/share/tomcat/webapps/ROOT/index.jsp 配置文件路徑: /usr/share/tomcat/
把裝好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
用新鏡像生成容器進行訪問bash
[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
若是想進入:app
[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
訪問看效果:ssh