1.安装docker
[root@iZ2ze82p1dogve7neb5tuoZ ~]# yum install docker
2.查看 docker 是否成功
[root@iZ2ze82p1dogve7neb5tuoZ ~]# docker
会显示一堆 docker 相关的命令:
Usage: docker COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/root/.docker")
-D, --debug Enable debug mode
--help Print usage
-H, --host list Daemon socket(s) to connect to (default [])
-l, --log-level string Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
container Manage containers
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
volume Manage volumes
Commands:
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
3.开启docker服务;查看docker服务状态
[root@iZ2ze82p1dogve7neb5tuoZ ~]# systemctl start docker
[root@iZ2ze82p1dogve7neb5tuoZ ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2018-04-04 21:51:39 CST; 9s ago
Docs: http://docs.docker.com
Main PID: 1537 (dockerd-current)
CGroup: /system.slice/docker.service
├─1537 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/l...
└─1543 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containe...
Apr 04 21:51:39 iZ2ze82p1dogve7neb5tuoZ dockerd-current[1537]: time="2018-04-04T21:51:39.754395415+08:00" level=info msg="Loading containers: start."
Apr 04 21:51:39 iZ2ze82p1dogve7neb5tuoZ dockerd-current[1537]: time="2018-04-04T21:51:39.790889447+08:00" level=info msg="Firewalld running: false"
Apr 04 21:51:39 iZ2ze82p1dogve7neb5tuoZ dockerd-current[1537]: time="2018-04-04T21:51:39.876020901+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.18.0.0/16. D... IP address"
Apr 04 21:51:39 iZ2ze82p1dogve7neb5tuoZ dockerd-current[1537]: time="2018-04-04T21:51:39.946205628+08:00" level=info msg="Loading containers: done."
Apr 04 21:51:39 iZ2ze82p1dogve7neb5tuoZ dockerd-current[1537]: time="2018-04-04T21:51:39.951686259+08:00" level=warning msg="failed to retrieve docker-runc version: unknown output format: runc v...0-rc2-dev\n"
Apr 04 21:51:39 iZ2ze82p1dogve7neb5tuoZ dockerd-current[1537]: time="2018-04-04T21:51:39.951738202+08:00" level=warning msg="failed to retrieve docker-init version"
Apr 04 21:51:39 iZ2ze82p1dogve7neb5tuoZ dockerd-current[1537]: time="2018-04-04T21:51:39.952302965+08:00" level=info msg="Daemon has completed initialization"
Apr 04 21:51:39 iZ2ze82p1dogve7neb5tuoZ dockerd-current[1537]: time="2018-04-04T21:51:39.952322364+08:00" level=info msg="Docker daemon" commit="774336d/1.13.1" graphdriver=overlay2 version=1.13.1
Apr 04 21:51:39 iZ2ze82p1dogve7neb5tuoZ systemd[1]: Started Docker Application Container Engine.
Apr 04 21:51:39 iZ2ze82p1dogve7neb5tuoZ dockerd-current[1537]: time="2018-04-04T21:51:39.976226569+08:00" level=info msg="API listen on /var/run/docker.sock"
Hint: Some lines were ellipsized, use -l to show in full.
[root@iZ2ze82p1dogve7neb5tuoZ ~]#
4.搜寻tomcat
[root@iZ2ze82p1dogve7neb5tuoZ ~]# docker search tomcat
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/tomcat Apache Tomcat is an open source implementa... 1782 [OK]
docker.io docker.io/dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 ba... 48 [OK]
docker.io docker.io/tomee Apache TomEE is an all-Apache Java EE cert... 48 [OK]
docker.io docker.io/davidcaste/alpine-tomcat Apache Tomcat 7/8 using Oracle Java 7/8 wi... 24 [OK]
docker.io docker.io/consol/tomcat-7.0 Tomcat 7.0.57, 8080, "admin/admin" 16 [OK]
docker.io docker.io/cloudesire/tomcat Tomcat server, 6/7/8 15 [OK]
docker.io docker.io/bitnami/tomcat Bitnami Tomcat Docker Image 13 [OK]
docker.io docker.io/jeanblanchard/tomcat Minimal Docker image with Apache Tomcat 8
docker.io docker.io/meirwa/spring-boot-tomcat-mysql-app a sample spring-boot app using tomcat and ... 8 [OK]
docker.io docker.io/tutum/tomcat Base docker image to run a Tomcat applicat... 8
docker.io docker.io/aallam/tomcat-mysql Debian, Oracle JDK, Tomcat & MySQL 6 [OK]
docker.io docker.io/rightctrl/tomcat CentOS , Oracle Java, tomcat application s... 3 [OK]
docker.io docker.io/99taxis/tomcat7 Tomcat7 1 [OK]
docker.io docker.io/amd64/tomcat Apache Tomcat is an open source implementa... 1
docker.io docker.io/camptocamp/tomcat-logback Docker image for tomcat with logback integ... 1 [OK]
docker.io docker.io/maluuba/tomcat7-java8 Tomcat7 with java8. 1
docker.io docker.io/primetoninc/tomcat Apache tomcat 8.5, 8.0, 7.0 1 [OK]
docker.io docker.io/awscory/tomcat tomcat 0
docker.io docker.io/buravelli9/tomcat-az-standards Tomcat image-AZ 0
docker.io docker.io/fabric8/tomcat-8 Fabric8 Tomcat 8 Image 0 [OK]
docker.io docker.io/jelastic/tomcat 0
docker.io docker.io/oobsri/tomcat8 Testing CI Jobs with different names. 0
docker.io docker.io/picoded/tomcat7 tomcat7 with jre8 and MANAGER_USER / MANAG... 0 [OK]
docker.io docker.io/s390x/tomcat Apache Tomcat is an open source implementa... 0
docker.io docker.io/swisstopo/service-print-tomcat backend tomcat for service-print "the true... 0
[root@iZ2ze82p1dogve7neb5tuoZ ~]#
5.下载tomcat镜像
[root@iZ2ze82p1dogve7neb5tuoZ ~]# docker pull docker.io/tomcat
Using default tag: latest
Trying to pull repository docker.io/library/tomcat ...
latest: Pulling from docker.io/library/tomcat
c73ab1c6897b: Pull complete
1ab373b3deae: Pull complete
b542772b4177: Pull complete
0bcc3741ab14: Pull complete
421d624d778d: Pull complete
26ad58237506: Pull complete
8dbabc90b2b8: Pull complete
982930be204d: Pull complete
80869be51738: Pull complete
ebc6831d2466: Pull complete
e1d0586dfcce: Pull complete
f84378b2ff18: Pull complete
Digest: sha256:d0447b3276a9e7ca7b68430a4bc790b1724a2e66b474b872b2d96d6f07487fd6
Status: Downloaded newer image for docker.io/tomcat:latest
[root@iZ2ze82p1dogve7neb5tuoZ ~]#
6.查看下载镜像
[root@iZ2ze82p1dogve7neb5tuoZ ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/tomcat latest 516082cd94fa 2 weeks ago 547 MB
[root@iZ2ze82p1dogve7neb5tuoZ ~]#
7.开启 tomcat 镜像 ,并配置端口映射
[root@iZ2ze82p1dogve7neb5tuoZ ~]# docker run -d -p 8080:8080 516082cd94fa
9621dbb1999e2530374689c4a5417452e5d96ad981d8a10e4e1e8c940056184c
8.查看docker进程
[root@iZ2ze82p1dogve7neb5tuoZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9621dbb1999e 516082cd94fa "catalina.sh run" 57 seconds ago Up 56 seconds 0.0.0.0:8080->8080/tcp competent_shockley
[root@iZ2ze82p1dogve7neb5tuoZ ~]#
9. 浏览器 连接 tomcat
http://ip:8080
SUCCESS!