【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 ~]#
上一篇: 【Linux系统之heartbeat 】
下一篇: 【Docker 命令集】