首页

关于docker常用应用部署如tomcat、centos等及常用docker命令实战操作过程步骤整理

标签:docker images,docker镜像下载,docker常用命令,docker镜像备份,docker镜像还原,docker tomcat,docker centos     发布时间:2018-08-11   

一、前言

关于在centos系统通过docker通过官方镜像站安装常用如tomcatcentos等虚拟应用容器,通过虚拟容器可以启动对各镜像实例,如启动多个mysql数据进行测试读写分离,因为docker容器应用用户操作空间数据保存时间周期在容器启动运行阶段,对于docker建议目前用户测试调试使用,它优势快速部署实施应用软件。

二、常用操作命令

1.tomcat安装、常用操作

#查找远程images可用网站@b@docker search tomcat@b@#下载远程到本地@b@docker pull  docker.io/tomcat@b@#查看本地images@b@docker images@b@#运行 -   若端口被占用,可以指定容器和主机的映射端口 前者是外围访问端口:后者是容器内部端口@b@docker run -p 8081:8080 docker.io/tomcat@b@# 使用以下命令来查看正在运行的容器@b@docker ps@b@#登录tomcat服务器 3cb43327475 - 容器id(CONTAINER_ID),通过上面doker ps查到@b@docker  exec -it   3cb43327475   /bin/bash @b@#把war包丢到宿主机 在丢到container里面丢到tomcat/webapps@b@docker cp demo.war 3cb43327475 :/usr/local/tomcat/webapps@b@#上述执行有个弊端就是 容器重启后项目就会不再了,下面是方式2启动 以挂载的方式启动@b@docker run -d -v /usr/docker_file/demo.war:/usr/local/tomcat/webapps/demo.war -p 8080:8080 docker.io/tomcat

2. centos安装常用操作

#查找远程images可用网站@b@docker search centos@b@#拉去本地@b@docker pull daocloud.io/library/centos:centos7.5.1804@b@#查看本地images@b@docker images@b@#启动@b@docker run -d -i -t <imageID> /bin/bash@b@#查看容器运行情况 @b@docker ps@b@# 登录虚拟的服务器@b@docker attach <ContainerID>

3.登录centos容器下安装ifconfg、ssh

[root@raid2t 桌面]# docker  run  -d  -i  -t 88ec626ba223  /bin/bash@b@f513d4193cffb20044b7f05f0085d34e76058b54e80c2bcd39622466bb816fea@b@[root@raid2t 桌面]# docker ps@b@CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES@b@f513d4193cff        88ec626ba223        "/bin/bash"         27 seconds ago      Up 27 seconds                           romantic_mayer      @b@[root@raid2t 桌面]# docker  attach  f513d4193cff@b@[root@f513d4193cff /]# ifconfig@b@bash: ifconfig: command not found@b@[root@f513d4193cff /]# yum search  ifconfig@b@Loaded plugins: fastestmirror, ovl@b@Determining fastest mirrors@b@ * base: mirrors.aliyun.com@b@ * extras: mirrors.cn99.com@b@ * updates: mirrors.aliyun.com@b@base                                                     | 3.6 kB     00:00     @b@extras                                                   | 3.4 kB     00:00     @b@updates                                                  | 3.4 kB     00:00     @b@(1/4): base/7/x86_64/group_gz                              | 166 kB   00:00     @b@(2/4): extras/7/x86_64/primary_db                          | 173 kB   00:00     @b@(3/4): updates/7/x86_64/primary_db                         | 4.3 MB   00:00     @b@(4/4): base/7/x86_64/primary_db                                                                                                                                                                                       | 5.9 MB  00:00:09     @b@============================== Matched: ifconfig ===============================@b@net-tools.x86_64 : Basic networking tools @b@[root@f513d4193cff /]# yum  install  net-tools.x86_64@b@Loaded plugins: fastestmirror, ovl@b@Loading mirror speeds from cached hostfile@b@ * base: mirrors.aliyun.com@b@ * extras: mirrors.cn99.com@b@ * updates: mirrors.aliyun.com@b@Resolving Dependencies@b@--> Running transaction check@b@---> Package net-tools.x86_64 0:2.0-0.22.20131004git.el7 will be installed@b@--> Finished Dependency Resolution@b@@b@Dependencies Resolved@b@@b@================================================================================@b@ Package         Arch         Version                          Repository  Size@b@================================================================================@b@Installing:@b@ net-tools       x86_64       2.0-0.22.20131004git.el7         base       305 k@b@@b@Transaction Summary@b@================================================================================@b@Install  1 Package@b@@b@Total download size: 305 k@b@Installed size: 917 k@b@Is this ok [y/d/N]: y@b@Downloading packages:@b@warning: /var/cache/yum/x86_64/7/base/packages/net-tools-2.0-0.22.20131004git.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY@b@Public key for net-tools-2.0-0.22.20131004git.el7.x86_64.rpm is not installed@b@net-tools-2.0-0.22.20131004git.el7.x86_64.rpm                                                                                                                                                                         | 305 kB  00:00:00     @b@Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7@b@Importing GPG key 0xF4A80EB5:@b@ Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"@b@ Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5@b@ Package    : centos-release-7-5.1804.el7.centos.2.x86_64 (@Updates)@b@ From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7@b@Is this ok [y/N]: y@b@Running transaction check@b@Running transaction test@b@Transaction test succeeded@b@Running transaction@b@  Installing : net-tools-2.0-0.22.20131004git.el7.x86_64                                                                                                                                                                                 1/1 @b@  Verifying  : net-tools-2.0-0.22.20131004git.el7.x86_64                                                                                                                                                                                 1/1 @b@@b@Installed:@b@  net-tools.x86_64 0:2.0-0.22.20131004git.el7                                                                                                                                                                                                @b@@b@Complete!@b@[root@f513d4193cff /]# ifconfig@b@eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500@b@        inet 172.17.0.3  netmask 255.255.0.0  broadcast 0.0.0.0@b@        inet6 fe80::42:acff:fe11:3  prefixlen 64  scopeid 0x20<link>@b@        ether 02:42:ac:11:00:03  txqueuelen 0  (Ethernet)@b@        RX packets 8044  bytes 11851181 (11.3 MiB)@b@        RX errors 0  dropped 0  overruns 0  frame 0@b@        TX packets 5274  bytes 336416 (328.5 KiB)@b@        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0@b@@b@lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536@b@        inet 127.0.0.1  netmask 255.0.0.0@b@        inet6 ::1  prefixlen 128  scopeid 0x10<host>@b@        loop  txqueuelen 0  (Local Loopback)@b@        RX packets 0  bytes 0 (0.0 B)@b@        RX errors 0  dropped 0  overruns 0  frame 0@b@        TX packets 0  bytes 0 (0.0 B)@b@        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0@b@[root@f513d4193cff /]# ping  192.168.1.1@b@PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.@b@64 bytes from 192.168.1.1: icmp_seq=1 ttl=63 time=0.584 ms@b@64 bytes from 192.168.1.1: icmp_seq=2 ttl=63 time=0.643 ms@b@64 bytes from 192.168.1.1: icmp_seq=3 ttl=63 time=0.525 ms@b@64 bytes from 192.168.1.1: icmp_seq=4 ttl=63 time=0.649 ms@b@^C@b@--- 192.168.1.1 ping statistics ---@b@4 packets transmitted, 4 received, 0% packet loss, time 3000ms@b@rtt min/avg/max/mdev = 0.525/0.600/0.649/0.053 ms@b@@b@[root@f513d4193cff /]# rpm  -qa|grep sshd@b@[root@f513d4193cff /]# rpm  -qa|grep ssh@b@openssh-7.4p1-16.el7.x86_64@b@openssh-server-7.4p1-16.el7.x86_64@b@libssh2-1.4.3-10.el7_2.1.x86_64@b@[root@f513d4193cff /]#@b@@b@[root@f513d4193cff /]# yum  install  -y  openssh-server@b@Loaded plugins: fastestmirror, ovl@b@Loading mirror speeds from cached hostfile@b@ * base: mirrors.aliyun.com@b@ * extras: mirrors.cn99.com@b@ * updates: mirrors.aliyun.com@b@Resolving Dependencies@b@--> Running transaction check@b@---> Package openssh-server.x86_64 0:7.4p1-16.el7 will be installed@b@--> Processing Dependency: openssh = 7.4p1-16.el7 for package: openssh-server-7.4p1-16.el7.x86_64@b@--> Processing Dependency: fipscheck-lib(x86-64) >= 1.3.0 for package: openssh-server-7.4p1-16.el7.x86_64@b@--> Processing Dependency: libwrap.so.0()(64bit) for package: openssh-server-7.4p1-16.el7.x86_64@b@--> Processing Dependency: libfipscheck.so.1()(64bit) for package: openssh-server-7.4p1-16.el7.x86_64@b@--> Running transaction check@b@---> Package fipscheck-lib.x86_64 0:1.4.1-6.el7 will be installed@b@--> Processing Dependency: /usr/bin/fipscheck for package: fipscheck-lib-1.4.1-6.el7.x86_64@b@---> Package openssh.x86_64 0:7.4p1-16.el7 will be installed@b@---> Package tcp_wrappers-libs.x86_64 0:7.6-77.el7 will be installed@b@--> Running transaction check@b@---> Package fipscheck.x86_64 0:1.4.1-6.el7 will be installed@b@--> Finished Dependency Resolution@b@@b@Dependencies Resolved@b@@b@============================================================================================================@b@ Package                         Arch                 Version                      Repository          Size@b@============================================================================================================@b@Installing:@b@ openssh-server                  x86_64               7.4p1-16.el7                 base               458 k@b@Installing for dependencies:@b@ fipscheck                       x86_64               1.4.1-6.el7                  base                21 k@b@ fipscheck-lib                   x86_64               1.4.1-6.el7                  base                11 k@b@ openssh                         x86_64               7.4p1-16.el7                 base               510 k@b@ tcp_wrappers-libs               x86_64               7.6-77.el7                   base                66 k@b@@b@Transaction Summary@b@============================================================================================================@b@Install  1 Package (+4 Dependent packages)@b@@b@Total download size: 1.0 M@b@Installed size: 3.0 M@b@Downloading packages:@b@(1/5): fipscheck-1.4.1-6.el7.x86_64.rpm                                              |  21 kB  00:00:00     @b@(2/5): fipscheck-lib-1.4.1-6.el7.x86_64.rpm                                          |  11 kB  00:00:00     @b@(3/5): openssh-7.4p1-16.el7.x86_64.rpm                                               | 510 kB  00:00:00     @b@(4/5): openssh-server-7.4p1-16.el7.x86_64.rpm                                        | 458 kB  00:00:00     @b@(5/5): tcp_wrappers-libs-7.6-77.el7.x86_64.rpm                                       |  66 kB  00:00:00     @b@------------------------------------------------------------------------------------------------------------@b@Total                                                                       3.4 MB/s | 1.0 MB  00:00:00     @b@Running transaction check@b@Running transaction test@b@Transaction test succeeded@b@Running transaction@b@  Installing : fipscheck-1.4.1-6.el7.x86_64                                                             1/5 @b@  Installing : fipscheck-lib-1.4.1-6.el7.x86_64                                                         2/5 @b@  Installing : openssh-7.4p1-16.el7.x86_64                                                              3/5 @b@  Installing : tcp_wrappers-libs-7.6-77.el7.x86_64                                                      4/5 @b@  Installing : openssh-server-7.4p1-16.el7.x86_64                                                       5/5 @b@  Verifying  : fipscheck-lib-1.4.1-6.el7.x86_64                                                         1/5 @b@  Verifying  : tcp_wrappers-libs-7.6-77.el7.x86_64                                                      2/5 @b@  Verifying  : fipscheck-1.4.1-6.el7.x86_64                                                             3/5 @b@  Verifying  : openssh-7.4p1-16.el7.x86_64                                                              4/5 @b@  Verifying  : openssh-server-7.4p1-16.el7.x86_64                                                       5/5 @b@@b@Installed:@b@  openssh-server.x86_64 0:7.4p1-16.el7                                                                      @b@@b@Dependency Installed:@b@  fipscheck.x86_64 0:1.4.1-6.el7         fipscheck-lib.x86_64 0:1.4.1-6.el7  openssh.x86_64 0:7.4p1-16.el7 @b@  tcp_wrappers-libs.x86_64 0:7.6-77.el7 @b@@b@Complete!

4.登录centos容器下安装nc

[root@f513d4193cff /]# yum  install  nc@b@Loaded plugins: fastestmirror, ovl@b@Loading mirror speeds from cached hostfile@b@ * base: mirrors.aliyun.com@b@ * extras: mirrors.cn99.com@b@ * updates: mirrors.aliyun.com@b@Resolving Dependencies@b@--> Running transaction check@b@---> Package nmap-ncat.x86_64 2:6.40-13.el7 will be installed@b@--> Processing Dependency: libpcap.so.1()(64bit) for package: 2:nmap-ncat-6.40-13.el7.x86_64@b@--> Running transaction check@b@---> Package libpcap.x86_64 14:1.5.3-11.el7 will be installed@b@--> Finished Dependency Resolution@b@@b@Dependencies Resolved@b@@b@============================================================================================================@b@ Package                  Arch                  Version                           Repository           Size@b@============================================================================================================@b@Installing:@b@ nmap-ncat                x86_64                2:6.40-13.el7                     base                205 k@b@Installing for dependencies:@b@ libpcap                  x86_64                14:1.5.3-11.el7                   base                138 k@b@@b@Transaction Summary@b@============================================================================================================@b@Install  1 Package (+1 Dependent package)@b@@b@Total download size: 343 k@b@Installed size: 740 k@b@Is this ok [y/d/N]: y@b@Downloading packages:@b@nmap-ncat-6.40-13.el7.x86_64.r FAILED                                          @b@http://mirrors.aliyun.com/centos/7.5.1804/os/x86_64/Packages/nmap-ncat-6.40-13.el7.x86_64.rpm: [Errno 12] Timeout on http://mirrors.aliyun.com/centos/7.5.1804/os/x86_64/Packages/nmap-ncat-6.40-13.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')@b@Trying other mirror.@b@libpcap-1.5.3-11.el7.x86_64.rp FAILED                                          @b@http://mirrors.aliyun.com/centos/7.5.1804/os/x86_64/Packages/libpcap-1.5.3-11.el7.x86_64.rpm: [Errno 12] Timeout on http://mirrors.aliyun.com/centos/7.5.1804/os/x86_64/Packages/libpcap-1.5.3-11.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')@b@Trying other mirror.@b@libpcap-1.5.3-11.el7.x86_64.rp FAILED                                          @b@http://ftp.sjtu.edu.cn/centos/7.5.1804/os/x86_64/Packages/libpcap-1.5.3-11.el7.x86_64.rpm: [Errno 14] curl#7 - "Failed to connect to 2001:da8:8000:6023::230: Network is unreachable"@b@Trying other mirror.@b@nmap-ncat-6.40-13.el7.x86_64.r FAILED                                          @b@http://mirrors.shu.edu.cn/centos/7.5.1804/os/x86_64/Packages/nmap-ncat-6.40-13.el7.x86_64.rpm: [Errno 12] Timeout on http://mirrors.shu.edu.cn/centos/7.5.1804/os/x86_64/Packages/nmap-ncat-6.40-13.el7.x86_64.rpm: (28, 'Connection timed out after 30001 milliseconds')@b@Trying other mirror.@b@libpcap-1.5.3-11.el7.x86_64.rp FAILED                                          @b@http://mirrors.cqu.edu.cn/CentOS/7.5.1804/os/x86_64/Packages/libpcap-1.5.3-11.el7.x86_64.rpm: [Errno 12] Timeout on http://mirrors.cqu.edu.cn/CentOS/7.5.1804/os/x86_64/Packages/libpcap-1.5.3-11.el7.x86_64.rpm: (28, 'Connection timed out after 30001 milliseconds')@b@Trying other mirror.@b@(1/2): libpcap-1.5.3-11.el7.x86_64.rpm                                               | 138 kB  00:00:01     @b@nmap-ncat-6.40-13.el7.x86_64.r FAILED                                          @b@http://mirrors.nju.edu.cn/centos/7.5.1804/os/x86_64/Packages/nmap-ncat-6.40-13.el7.x86_64.rpm: [Errno 12] Timeout on http://mirrors.nju.edu.cn/centos/7.5.1804/os/x86_64/Packages/nmap-ncat-6.40-13.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')@b@Trying other mirror.@b@(2/2): nmap-ncat-6.40-13.el7.x86_64.rpm                                              | 205 kB  00:00:00     @b@------------------------------------------------------------------------------------------------------------@b@Total                                                                       3.2 kB/s | 343 kB  00:01:46     @b@Running transaction check@b@Running transaction test@b@Transaction test succeeded@b@Running transaction@b@  Installing : 14:libpcap-1.5.3-11.el7.x86_64                                                           1/2 @b@  Installing : 2:nmap-ncat-6.40-13.el7.x86_64                                                           2/2 @b@  Verifying  : 14:libpcap-1.5.3-11.el7.x86_64                                                           1/2 @b@  Verifying  : 2:nmap-ncat-6.40-13.el7.x86_64                                                           2/2 @b@@b@Installed:@b@  nmap-ncat.x86_64 2:6.40-13.el7                                                                            @b@@b@Dependency Installed:@b@  libpcap.x86_64 14:1.5.3-11.el7                                                                            @b@@b@Complete!

5.centos镜像备份还原

[root@raid2t docker-images-bak]# docker  images@b@REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE@b@daocloud.io/library/tomcat   latest              9e2a01704df0        10 days ago         462.5 MB@b@daocloud.io/library/centos   centos7.5.1804      88ec626ba223        9 weeks ago         199.7 MB@b@[root@raid2t docker-images-bak]# docker  save  -o  /home/docker-images-bak/centos.tar  daocloud.io/library/centos@b@[root@raid2t docker-images-bak]# ls -l@b@总用量 202976@b@-rw-r--r--. 1 root root 207846400 8月  11 20:41 centos.tar@b@@b@[root@raid2t 桌面]# docker images@b@REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE@b@daocloud.io/library/tomcat   latest              9e2a01704df0        10 days ago         462.5 MB@b@daocloud.io/library/centos   centos7.5.1804      88ec626ba223        9 weeks ago         199.7 MB@b@[root@raid2t 桌面]# docker rmi  88ec626ba223@b@Error response from daemon: Conflict, cannot delete 88ec626ba223 because the container f513d4193cff is using it, use -f to force@b@Error: failed to remove images: [88ec626ba223]@b@[root@raid2t 桌面]# docker rmi -f  88ec626ba223@b@Untagged: daocloud.io/library/centos:centos7.5.1804@b@Deleted: 88ec626ba223582f0fc2c0db20a80ee2d82f12e9e0ae0a0149e7ef2ad3d7c8bc@b@Deleted: b298d692482d46711a3874419f73b2d61e6297fdd029d9e20a086c7117406eef@b@Deleted: 29466d114cd8c0ae98a536a0a344b7634aa7223966fa2dfa036aeb4aaa4e6f11@b@[root@raid2t 桌面]# docker images@b@REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE@b@daocloud.io/library/tomcat   latest              9e2a01704df0        10 days ago         462.5 MB@b@[root@raid2t 桌面]# cd  /home/docker-images-bak/@b@[root@raid2t docker-images-bak]# ls -l@b@总用量 202976@b@-rw-r--r--. 1 root root 207846400 8月  11 20:41 centos.tar@b@[root@raid2t docker-images-bak]# pwd@b@/home/docker-images-bak@b@[root@raid2t docker-images-bak]# docker load -i /home/docker-images-bak/centos.tar @b@[root@raid2t docker-images-bak]# docker images@b@REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE@b@daocloud.io/library/tomcat   latest              9e2a01704df0        10 days ago         462.5 MB@b@daocloud.io/library/centos   centos7.5.1804      88ec626ba223        9 weeks ago         199.7 MB

6.docker stop停止/remove删除所有容器t

$ docker ps // 查看所有正在运行容器@b@$ docker stop containerId // containerId 是容器的ID@b@@b@$ docker ps -a // 查看所有容器@b@$ docker ps -a -q // 查看所有容器ID@b@@b@$ docker stop $(docker ps -a -q) //  stop停止所有容器@b@$ docker  rm $(docker ps -a -q) //   remove删除所有容器
  • <<相关内容>>
<<热门下载>>