`
gaojingsong
  • 浏览: 1181800 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

【Docker之Tomcat容器的启动与停止】

阅读更多

Last login: Mon Sep  3 09:14:33 2018 from 192.168.1.102

[root@bogon ~]# systemctl start docker

[root@bogon ~]# docker images

REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE

docker.io/haproxy                      latest              0e70860c9b84        3 days ago          69.5 MB

docker.io/nginx                        latest              71c43202b8ac        4 days ago          109 MB

docker.io/mongo-express                latest              d3f93978bf53        9 days ago          97.2 MB

docker.io/mongo                        latest              a41c82c0998a        10 days ago         380 MB

docker.io/kibana                       latest              1f30aec345e3        10 days ago         390 MB

docker.io/elasticsearch                latest              097d037f8ff8        10 days ago         486 MB

docker.io/resin/rpi-raspbian           latest              365783567b86        2 weeks ago         126 MB

docker.io/jetty                        latest              07b6d9a3f5d2        2 weeks ago         453 MB

docker.io/mysql                        latest              29e0ae3b69b9        2 weeks ago         484 MB

docker.io/zookeeper                    latest              29d319df9c13        2 weeks ago         149 MB

docker.io/redis                        latest              4e8db158f18d        4 weeks ago         83.4 MB

docker.io/wurstmeister/kafka           latest              e4c6cedf70f9        4 weeks ago         312 MB

docker.io/storm                        latest              0adcd94d5ef3        7 weeks ago         314 MB

docker.io/million12/varnish            latest              d4b511cda342        4 months ago        309 MB

docker.io/zeusxiao/static-dev-server   latest              ab422d1a9e84        13 months ago       682 MB

docker.io/tomcat                       8.5.16              b226d7ee3462        13 months ago       292 MB

docker.io/longhronshens/mycat-docker   latest              f9a4ece7c742        13 months ago       793 MB

docker.io/airdock/oracle-jdk           latest              c64f85af84fa        16 months ago       533 MB

docker.io/java                         latest              d23bdf5b1b1b        19 months ago       643 MB

docker.io/sebp/lighttpd                latest              6b681cc70957        22 months ago       8.53 MB

[root@bogon ~]# docker ps -a

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@bogon ~]# docker run -d -p 3306:8080 docker.io/tomcat

正确方式:容器ID

Unable to find image 'docker.io/tomcat:latest' locally

Trying to pull repository docker.io/library/tomcat ... 

latest: Pulling from docker.io/library/tomcat

55cbf04beb70: Already exists 

1607093a898c: Already exists 

9a8ea045c926: Already exists 

1290813abd9d: Already exists 

8a6b982ad6d7: Already exists 

abb029e68402: Already exists 

d068d0a738e5: Already exists 

42ee47bb0c52: Already exists 

ae9c861aed25: Pull complete 

60bba9d0dc8d: Pull complete 

091c11d70257: Pull complete 

869034383fc7: Pull complete 

Digest: sha256:eab533908d6c7760a84a5edbb4490b648484941dfa708a1c5f4286db8caab825

Status: Downloaded newer image for docker.io/tomcat:latest

6a95a9f14a490602a3db63382ee45c244baaa882e31df60b8f3acfe554405f5e

[root@bogon ~]# docker run -d -p 3306:8080   b226d7ee3462

1b2bf089bac04a0f72fb5e249055315e938783f4d8b36753ecb320ff7339115d

/usr/bin/docker-current: Error response from daemon: driver failed programming external connectivity on endpoint vibrant_kalam (3f9d4e373fb74db41c877df25a9479605a233c350913579db10031d8e9031a8f): Bind for 0.0.0.0:3306 failed: port is already allocated.

[root@bogon ~]# docker run -d -p 1521:8080   b226d7ee3462    

f78eed9a8e4d3f63c0ca4b10049cd942d81b0c5f5e4c165dd88d27e5471eaa33

[root@bogon ~]# docker ps -a

CONTAINER ID        IMAGE         COMMAND     CREATED     STATUS      PORTS         NAMES

f78eed9a8e4d        b226d7ee3462        "catalina.sh run"   5 seconds ago       Up 4 seconds        0.0.0.0:1521->8080/tcp   sleepy_fermi

1b2bf089bac0        b226d7ee3462        "catalina.sh run"   30 seconds ago      Created                                      vibrant_kalam

6a95a9f14a49        docker.io/tomcat    "catalina.sh run"   53 seconds ago      Up 52 seconds       0.0.0.0:3306->8080/tcp   serene_ride

[root@bogon ~]# 


 docker run -d -p 8888:8080 test/tomcat

-d:表示指定容器后台运行

-p:表示宿主机的8080端口对外映射暴露为8888端口

验证:


 


停止

[root@bogon ~]# docker stop  --help

 

Usage:  docker stop [OPTIONS] CONTAINER [CONTAINER...]

 

Stop one or more running containers

 

Options:

      --help       Print usage

  -t, --time int   Seconds to wait for stop before killing it (default 10)

[root@bogon ~]# docker kill  --help    

 

Usage:  docker kill [OPTIONS] CONTAINER [CONTAINER...]

 

Kill one or more running containers

 

Options:

      --help            Print usage

  -s, --signal string   Signal to send to the container (default "KILL")

[root@bogon ~]# 



 docker stop 与 docker kill 的区别

Docker本身提供了两种终止容器运行的方式,即docker stop与docker kill。

 

docker stop

先来说说docker stop吧,当我们用docker stop命令来停掉容器的时候,docker默认会允许容器中的应用程序有10秒的时间用以终止运行。所以我们查看docker stop命令帮助的时候,会有如下的提示:

 

 

docker kill

接着我们来看看docker kill命令,默认情况下,docker kill命令不会给容器中的应用程序有任何gracefully shutdown的机会。它会直接发出SIGKILL的系统信号,以强行终止容器中程序的运行。通过查看docker kill命令的帮助,我们可以看到,除了默认发送SIGKILL信号外,还允许我们发送一些自定义的系统信号:


 

 

 

备注:

Last login: Sun Sep  2 03:12:58 2018 from 192.168.1.102

[root@bogon ~]# docker run --help

 

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

 

Run a command in a new container

 

Options:

      --add-host list                         Add a custom host-to-IP mapping (host:ip) (default [])

  -a, --attach list                           Attach to STDIN, STDOUT or STDERR (default [])

      --blkio-weight uint16                   Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)

      --blkio-weight-device weighted-device   Block IO weight (relative device weight) (default [])

      --cap-add list                          Add Linux capabilities (default [])

      --cap-drop list                         Drop Linux capabilities (default [])

      --cgroup-parent string                  Optional parent cgroup for the container

      --cidfile string                        Write the container ID to the file

      --cpu-count int                         CPU count (Windows only)

      --cpu-percent int                       CPU percent (Windows only)

      --cpu-period int                        Limit CPU CFS (Completely Fair Scheduler) period

      --cpu-quota int                         Limit CPU CFS (Completely Fair Scheduler) quota

      --cpu-rt-period int                     Limit CPU real-time period in microseconds

      --cpu-rt-runtime int                    Limit CPU real-time runtime in microseconds

  -c, --cpu-shares int                        CPU shares (relative weight)

      --cpus decimal                          Number of CPUs (default 0.000)

      --cpuset-cpus string                    CPUs in which to allow execution (0-3, 0,1)

      --cpuset-mems string                    MEMs in which to allow execution (0-3, 0,1)

      --credentialspec string                 Credential spec for managed service account (Windows only)

  -d, --detach                                Run container in background and print container ID

      --detach-keys string                    Override the key sequence for detaching a container

      --device list                           Add a host device to the container (default [])

      --device-read-bps throttled-device      Limit read rate (bytes per second) from a device (default [])

      --device-read-iops throttled-device     Limit read rate (IO per second) from a device (default [])

      --device-write-bps throttled-device     Limit write rate (bytes per second) to a device (default [])

      --device-write-iops throttled-device    Limit write rate (IO per second) to a device (default [])

      --disable-content-trust                 Skip image verification (default true)

      --dns list                              Set custom DNS servers (default [])

      --dns-option list                       Set DNS options (default [])

      --dns-search list                       Set custom DNS search domains (default [])

      --entrypoint string                     Overwrite the default ENTRYPOINT of the image

  -e, --env list                              Set environment variables (default [])

      --env-file list                         Read in a file of environment variables (default [])

      --expose list                           Expose a port or a range of ports (default [])

      --group-add list                        Add additional groups to join (default [])

      --health-cmd string                     Command to run to check health

      --health-interval duration              Time between running the check (ns|us|ms|s|m|h) (default 0s)

      --health-retries int                    Consecutive failures needed to report unhealthy

      --health-timeout duration               Maximum time to allow one check to run (ns|us|ms|s|m|h) (default 0s)

      --help                                  Print usage

  -h, --hostname string                       Container host name

      --init                                  Run an init inside the container that forwards signals and reaps processes

      --init-path string                      Path to the docker-init binary

  -i, --interactive                           Keep STDIN open even if not attached

      --io-maxbandwidth string                Maximum IO bandwidth limit for the system drive (Windows only)

      --io-maxiops uint                       Maximum IOps limit for the system drive (Windows only)

      --ip string                             Container IPv4 address (e.g. 172.30.100.104)

      --ip6 string                            Container IPv6 address (e.g. 2001:db8::33)

      --ipc string                            IPC namespace to use

      --isolation string                      Container isolation technology

      --kernel-memory string                  Kernel memory limit

  -l, --label list                            Set meta data on a container (default [])

      --label-file list                       Read in a line delimited file of labels (default [])

      --link list                             Add link to another container (default [])

      --link-local-ip list                    Container IPv4/IPv6 link-local addresses (default [])

      --log-driver string                     Logging driver for the container

      --log-opt list                          Log driver options (default [])

      --mac-address string                    Container MAC address (e.g. 92:d0:c6:0a:29:33)

  -m, --memory string                         Memory limit

      --memory-reservation string             Memory soft limit

      --memory-swap string                    Swap limit equal to memory plus swap: '-1' to enable unlimited swap

      --memory-swappiness int                 Tune container memory swappiness (0 to 100) (default -1)

      --name string                           Assign a name to the container

      --network string                        Connect a container to a network (default "default")

      --network-alias list                    Add network-scoped alias for the container (default [])

      --no-healthcheck                        Disable any container-specified HEALTHCHECK

      --oom-kill-disable                      Disable OOM Killer

      --oom-score-adj int                     Tune host's OOM preferences (-1000 to 1000)

      --pid string                            PID namespace to use

      --pids-limit int                        Tune container pids limit (set -1 for unlimited)

      --privileged                            Give extended privileges to this container

  -p, --publish list                          Publish a container's port(s) to the host (default [])

  -P, --publish-all                           Publish all exposed ports to random ports

      --read-only                             Mount the container's root filesystem as read only

      --restart string                        Restart policy to apply when a container exits (default "no")

      --rm                                    Automatically remove the container when it exits

      --runtime string                        Runtime to use for this container

      --security-opt list                     Security Options (default [])

      --shm-size string                       Size of /dev/shm, default value is 64MB

      --sig-proxy                             Proxy received signals to the process (default true)

      --stop-signal string                    Signal to stop a container, SIGTERM by default (default "SIGTERM")

      --stop-timeout int                      Timeout (in seconds) to stop a container

      --storage-opt list                      Storage driver options for the container (default [])

      --sysctl map                            Sysctl options (default map[])

      --tmpfs list                            Mount a tmpfs directory (default [])

  -t, --tty                                   Allocate a pseudo-TTY

      --ulimit ulimit                         Ulimit options (default [])

  -u, --user string                           Username or UID (format: <name|uid>[:<group|gid>])

      --userns string                         User namespace to use

      --uts string                            UTS namespace to use

  -v, --volume list                           Bind mount a volume (default [])

      --volume-driver string                  Optional volume driver for the container

      --volumes-from list                     Mount volumes from the specified container(s) (default [])

  -w, --workdir string                        Working directory inside the container

[root@bogon ~]# 

  • 大小: 114.7 KB
  • 大小: 124.1 KB
  • 大小: 89.3 KB
  • 大小: 71.9 KB
  • 大小: 52 KB
0
0
分享到:
评论

相关推荐

    解决docker容器启动后马上退出的问题

    最后证明这个方法是可行的,在实验过程中遇到一个问题,容器启动后会马上停止。 经查阅资料: Docker容器同时只能管理一个进程,如果这个进程退出那么容器也就退出了,但这不表示容器只能运行一个进程(其他进程可在...

    Docker容器详解.docx

    4.4. 启动已停止运行的容器 17 4.5. 停止容器 17 4.6. 删除容器 17 4.7. 文件拷贝 18 4.8. 目录挂载 18 4.9. 查看容器ip地址 19 4.10. 查看容器镜像的详细信息 19 5. Docker 镜像使用 19 5.1. 列出镜像列表 ...

    Docker安装与指令

    Docker 容器操作包括:容器的启动、容器的停止、容器的重启和容器的删除。 JDK、MySQL、Tomcat、Nginx 等容器的部署方法可以通过 DockerFile 来实现。DockerFile 是一个文本文件,用于定义 Docker 镜像的构建过程。...

    虚拟机与docker用法

    常用的服务命令包括启动、停止、重启、开机自动启动、禁止开机自动启动和查看服务状态等。 九、Zip格式的解压与压缩 Zip是一种常用的压缩格式,用于压缩和解压缩文件。安装zip工具可以使用命令`yum -y install zip...

    container-arsenal:用于安全评估和 CTF 的 docker 容器集合。 用于启动、停止和管理它们的命令行工具

    container-arsenal ( car ) 是docker 容器的集合,已被证明在安全评估和CTF期间很有用。 每个容器由一个docker-compose文件及其相应的资源表示。 此外,容器库提供了一个可用于管理容器的Python脚本。 描述 在安全...

    部署Tomcat服务器

    1. `bin`:包含了Tomcat的启动和停止脚本,如`startup.bat`和`shutdown.bat`。 2. `conf`:存放Tomcat的配置文件,如`server.xml`、`web.xml`等。 3. `webapps`:这是应用部署的默认目录,将Web应用程序的WAR包或...

    docker快速构建disconf镜像

    执行完成之后,就可以通过docker ps 看到启动的容器 root@ubuntu:/home/anan/docker/docker_disconf-master# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES de596887acac conf_nginx:0.0.1 ...

    Docker Volumn容器间共享数据的实现

    这种方式便于管理,尤其在需要大量共享数据的场景下,可以避免在每个容器启动时都需要指定长长的卷挂载参数。 总之,Docker卷为容器间数据共享提供了灵活性,使得容器化应用的数据持久化和数据共享变得更加简单和...

    Tomcat技术培训

    - **Servlet容器**:Tomcat的核心功能之一是作为一个Servlet容器,它能够承载并运行基于Servlet的应用程序。 - **组件结构**: - **Server**:整个Tomcat服务器的基础,包含多组服务,负责管理和启动各个Service。...

    服务器部署多个tomcat方法

    每个Tomcat实例需要有自己的启动和停止脚本,通常在`bin`目录下。你可以创建软链接或者复制并修改原始的`catalina.sh`或`catalina.bat`,并传入相应的`CATALINA_BASE`。 ### 5. **使用虚拟主机** Tomcat 6及以上...

    Tomcat与Java.Web开发技术详解

    3. **Tomcat安装与配置**:涉及下载Tomcat,设置环境变量,启动和停止服务器,以及配置server.xml文件以管理多个虚拟主机和应用。 4. **Tomcat目录结构**:如WEB-INF目录包含web.xml(部署描述符),classes和lib...

    Apache-tomcat-8.0.0 for centos

    5. **启动和管理Tomcat**:使用`bin/startup.sh`和`bin/shutdown.sh`脚本启动和停止Tomcat服务。 6. **防火墙设置**:如果需要,配置防火墙规则以允许外部访问Tomcat服务。 7. **部署应用**:将Web应用程序的WAR...

    分享一个linux环境下在tomcat中发布项目的方式

    在生产环境中,为了保证服务的稳定性和安全性,通常会使用更复杂的方法来部署,如使用版本控制系统、自动化部署工具(如Jenkins、GitLab CI/CD)以及容器化技术(Docker)。不过,上述步骤为基本的手动部署过程,...

    有关容器的六大误区和八大正确场景.docx

    同时,虚拟机启动速度也在不断优化,如通过减少镜像下载时间等手段,已可达到接近容器启动的速度。因此,启动速度并非容器相对于虚拟机的主要优势,且容器的隔离性相对较弱。 **误区二:容器轻量级,适合运行大量...

    docker常用命令

    1。 docker run -it -p 8080:8080 tomcat ...在使用 -d 参数时,容器启动后会进入后台。此时想要进入容器,可以通过以下指令进入: docker attach 此退出容器终端,会导致容器的停止。 docker exec

    基于SpringBoot+Dubbo的微服务框架-SpringBoot-Dubbo-Docker-Jenkins.zip

    Docker容器轻量级、隔离性好,可以快速启动和停止,极大地提高了资源利用率和部署速度。在微服务架构中,每个服务都可以作为一个独立的Docker容器运行,便于管理和扩展。 【Jenkins】是一个开源的持续集成/持续交付...

Global site tag (gtag.js) - Google Analytics