Docker 安装Nginx
1.搜索镜像
# docker search nginx
[root@wangcai ~]# docker search nginx
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
redhat.com registry.access.redhat.com/ubi8/nginx-118 Platform for running nginx 1.18 or building ... 0
redhat.com registry.access.redhat.com/rhscl/nginx-18-rhel7 Nginx 1.8 server and a reverse proxy server 0
redhat.com registry.access.redhat.com/rhscl/nginx-112-rhel7 Nginx is a web server and a reverse proxy se... 0
docker.io docker.io/library/nginx Official build of Nginx. 15759 [OK]
2.下载镜像最近版本的镜像
# docker pull docker.io/library/nginx
[root@wangcai ~]# docker pull docker.io/library/nginx
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Trying to pull docker.io/library/nginx:latest...
Getting image source signatures
Copying blob 858292fd2e56 skipped: already exists
Copying blob fca7e12d1754 skipped: already exists
Copying blob b380bbd43752 skipped: already exists
Copying blob a4723e260b6f [--------------------------------------] 0.0b / 0.0b
Copying blob 745ab57616cb [--------------------------------------] 0.0b / 0.0b
Copying blob 1c84ebdff681 [--------------------------------------] 0.0b / 0.0b
Copying config 87a94228f1 done
Writing manifest to image destination
Storing signatures
87a94228f133e2da99cb16d653cd1373c5b4e8689956386c1c12b60a20421a02
3.启动镜像并映射宿主机端口
# docker run -d --name nginx -p 3344:80 ngxin
[root@wangcai ~]# docker run --name ngixn -d -p 3344:80 nginx
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
6367b5ba1058091f81ba0e02deae8004cef8df6bbdfe4826b051f710791cf489
4.通过本机地址端口访问 是否启动并映射成功
# curl http:localhost:3344
6367b5ba1058091f81ba0e02deae8004cef8df6bbdfe4826b051f710791cf489
[root@wangcai ~]# curl http://localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
5.查看启动的镜像配置信息
# docker inspect 6367b5ba1058091f81ba0(镜像ID)
[root@wangcai ~]# docker inspect 6367b5ba1058091f81ba0e02deae8004cef8df6bbdfe4826b051f710791cf489
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
[
{
"Id": "6367b5ba1058091f81ba0e02deae8004cef8df6bbdfe4826b051f710791cf489",
"Created": "2021-11-06T12:19:42.848103977+08:00",
"Path": "/docker-entrypoint.sh",
"Args": [
"nginx",
"-g",
"daemon off;"
],
"State": {
"OciVersion": "1.0.2-dev",
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 42150,
"ConmonPid": 42139,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-11-06T12:19:43.117252667+08:00",
"FinishedAt": "0001-01-01T00:00:00Z",
"Healthcheck": {
"Status": "",
"FailingStreak": 0,
"Log": null
}
},
"Image": "87a94228f133e2da99cb16d653cd1373c5b4e8689956386c1c12b60a20421a02",
"ImageName": "docker.io/library/nginx:latest",
"Rootfs": "",
"Pod": "",
"ResolvConfPath": "/run/containers/storage/overlay-containers/6367b5ba1058091f81ba0e02deae8004cef8df6bbdfe4826b051f710791cf489/userdata/resolv.conf",
"HostnamePath": "/run/containers/storage/overlay-containers/6367b5ba1058091f81ba0e02deae8004cef8df6bbdfe4826b051f710791cf489/userdata/hostname",
"HostsPath": "/run/containers/storage/overlay-containers/6367b5ba1058091f81ba0e02deae8004cef8df6bbdfe4826b051f710791cf489/userdata/hosts",
"StaticDir": "/var/lib/containers/storage/overlay-containers/6367b5ba1058091f81ba0e02deae8004cef8df6bbdfe4826b051f710791cf489/userdata",
"OCIConfigPath": "/var/lib/containers/storage/overlay-containers/6367b5ba1058091f81ba0e02deae8004cef8df6bbdfe4826b051f710791cf489/userdata/config.json",
"OCIRuntime": "runc",
"ConmonPidFile": "/run/containers/storage/overlay-containers/6367b5ba1058091f81ba0e02deae8004cef8df6bbdfe4826b051f710791cf489/userdata/conmon.pid",
"PidFile": "/run/containers/storage/overlay-containers/6367b5ba1058091f81ba0e02deae8004cef8df6bbdfe4826b051f710791cf489/userdata/pidfile",
"Name": "ngixn",
"RestartCount": 0,
"Driver": "overlay",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"EffectiveCaps": [
"CAP_CHOWN",
"CAP_DAC_OVERRIDE",
"CAP_FOWNER",
"CAP_FSETID",
"CAP_KILL",
"CAP_NET_BIND_SERVICE",
"CAP_NET_RAW",
"CAP_SETFCAP",
"CAP_SETGID",
"CAP_SETPCAP",
"CAP_SETUID",
"CAP_SYS_CHROOT"
],
"BoundingCaps": [
"CAP_CHOWN",
"CAP_DAC_OVERRIDE",
"CAP_FOWNER",
"CAP_FSETID",
"CAP_KILL",
"CAP_NET_BIND_SERVICE",
"CAP_NET_RAW",
"CAP_SETFCAP",
"CAP_SETGID",
"CAP_SETPCAP",
"CAP_SETUID",
"CAP_SYS_CHROOT"
],
"ExecIDs": [],
"GraphDriver": {
"Name": "overlay",
"Data": {
"LowerDir": "/var/lib/containers/storage/overlay/31c2de5d169dfd3dec8f4fcbed9e14b8595aba0026ecae5cb8a6c64279ac92d9/diff:/var/lib/containers/storage/overlay/374f3e479a4c014d312a1d5307a2325157d790a42e05123118513287158227c0/diff:/var/lib/containers/storage/overlay/d0bb91551c68349e715162671ef0696224b981e87ca12383339a56826c6cd57b/diff:/var/lib/containers/storage/overlay/68c3014305961fbc3b506f2fcafdacc4e6a0e8c9e47b94903c09983cf4e0eb68/diff:/var/lib/containers/storage/overlay/efde563e041fb4c8df07bd2a180938196cbedad662cdcfeff36ee419afb7e3ae/diff:/var/lib/containers/storage/overlay/e81bff2725dbc0bf2003db10272fef362e882eb96353055778a66cda430cf81b/diff",
"MergedDir": "/var/lib/containers/storage/overlay/7abe6563dbce59615de2d5ba481dc6da00024f0b95a8fd0ea9c20b8f31b69a40/merged",
"UpperDir": "/var/lib/containers/storage/overlay/7abe6563dbce59615de2d5ba481dc6da00024f0b95a8fd0ea9c20b8f31b69a40/diff",
"WorkDir": "/var/lib/containers/storage/overlay/7abe6563dbce59615de2d5ba481dc6da00024f0b95a8fd0ea9c20b8f31b69a40/work"
}
},
"Mounts": [],
"Dependencies": [],
"NetworkSettings": {
"EndpointID": "",
"Gateway": "10.88.0.1",
"IPAddress": "10.88.0.10",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "de:40:86:40:cf:fd",
"Bridge": "",
"SandboxID": "",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "3344"
}
]
},
"SandboxKey": "/run/netns/cni-2f695fe3-0745-ef97-798d-932b3b74b02d",
"Networks": {
"podman": {
"EndpointID": "",
"Gateway": "10.88.0.1",
"IPAddress": "10.88.0.10",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "de:40:86:40:cf:fd",
"NetworkID": "podman",
"DriverOpts": null,
"IPAMConfig": null,
"Links": null
}
}
},
"ExitCommand": [
"/usr/bin/podman",
"--root",
"/var/lib/containers/storage",
"--runroot",
"/run/containers/storage",
"--log-level",
"warning",
"--cgroup-manager",
"systemd",
"--tmpdir",
"/run/libpod",
"--runtime",
"runc",
"--storage-driver",
"overlay",
"--storage-opt",
"overlay.mountopt=nodev,metacopy=on",
"--events-backend",
"file",
"container",
"cleanup",
"6367b5ba1058091f81ba0e02deae8004cef8df6bbdfe4826b051f710791cf489"
],
"Namespace": "",
"IsInfra": false,
"Config": {
"Hostname": "6367b5ba1058",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TERM=xterm",
"container=podman",
"PKG_RELEASE=1~buster",
"NGINX_VERSION=1.21.3",
"NJS_VERSION=0.6.2",
"HOME=/root",
"HOSTNAME=6367b5ba1058"
],
"Cmd": [
"nginx",
"-g",
"daemon off;"
],
"Image": "docker.io/library/nginx:latest",
"Volumes": null,
"WorkingDir": "/",
"Entrypoint": "/docker-entrypoint.sh",
"OnBuild": null,
"Labels": {
"maintainer": "NGINX Docker Maintainers \u003cdocker-maint@nginx.com\u003e"
},
"Annotations": {
"io.container.manager": "libpod",
"io.kubernetes.cri-o.Created": "2021-11-06T12:19:42.848103977+08:00",
"io.kubernetes.cri-o.TTY": "false",
"io.podman.annotations.autoremove": "FALSE",
"io.podman.annotations.init": "FALSE",
"io.podman.annotations.privileged": "FALSE",
"io.podman.annotations.publish-all": "FALSE",
"org.opencontainers.image.stopSignal": "3"
},
"StopSignal": 3,
"CreateCommand": [
"/usr/bin/podman",
"run",
"--name",
"ngixn",
"-d",
"-p",
"3344:80",
"nginx"
],
"Umask": "0022",
"Timeout": 0,
"StopTimeout": 10
},
"HostConfig": {
"Binds": [],
"CgroupManager": "systemd",
"CgroupMode": "host",
"ContainerIDFile": "",
"LogConfig": {
"Type": "k8s-file",
"Config": null,
"Path": "/var/lib/containers/storage/overlay-containers/6367b5ba1058091f81ba0e02deae8004cef8df6bbdfe4826b051f710791cf489/userdata/ctr.log",
"Tag": "",
"Size": "0B"
},
"NetworkMode": "bridge",
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "3344"
}
]
},
"RestartPolicy": {
"Name": "",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": [],
"CapDrop": [
"CAP_AUDIT_WRITE",
"CAP_MKNOD"
],
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": [],
"GroupAdd": [],
"IpcMode": "private",
"Cgroup": "",
"Cgroups": "default",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "private",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": [],
"Tmpfs": {},
"UTSMode": "private",
"UsernsMode": "",
"ShmSize": 65536000,
"Runtime": "oci",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": 0,
"OomKillDisable": false,
"PidsLimit": 2048,
"Ulimits": [
{
"Name": "RLIMIT_NOFILE",
"Soft": 1048576,
"Hard": 1048576
},
{
"Name": "RLIMIT_NPROC",
"Soft": 4194304,
"Hard": 4194304
}
],
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"CgroupConf": null
}
}
]
Docker 安装Tomcat
1.官方命令(用完就删除容器,不推荐需要重新配置容器)
# docker run -it -rm tomcat
2.常用启动命令
# docker run --name tomcat -d -p 8080:8080 tomcat (停止后可以通过docker start asdasd(容器ID启动))
[root@wangcai ~]# docker run -it -d --name tomcat -p 8080:8080 tomcat
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
1aaad1993508e83accc967387143aa6200c668869731857ec0cdbecb52ec1eb7
3.访问本地,查看是否成功
# curl http://localhost:8080
[root@wangcai ~]# curl localhost:8080
<!doctype html><html lang="en"><head><title>HTTP Status 404 鈥� Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {colorwhite;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 鈥� Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The origin servr did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache Tomcat/10.0.12</h3></body></html>[root@wangcai ~]#
Docker 安装ES
1.拉取镜像(需要携带版本号,不然拉不下来)
# docker pull docker.io/library/elasticsearch:6.5.0
2.启动命令(携带配置启动,控制es启动内存)
# docker run -it --name es -d -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS='-Xms256m -Xmx512m' elasticsearch
[root@wangcai ~]# docker run -it --name es -d -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS='-Xms256m -Xmx512m' elasticsearch
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
6a529c271428a255638d9dab212c84293f8b4f8d391f063dae802461807be4df
[root@wangcai ~]# docker ps
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6a529c271428 docker.io/library/elasticsearch:6.5.0 eswrapper 3 seconds ago Up 3 seconds ago 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp es
3.访问本地,查看是否成功(失败了 我的天,还在找问题)
# curl http://localhost:9200
[root@wangcai ~]# curl localhost:9200
curl: (7) Failed to connect to localhost port 9200: 拒绝连接
Docker 安装MYSQL
1.拉取镜像
# docker pull docker.io/library/mysql
2.在宿主机创建与容器内对应的卷挂载目录
# cd /root
# mkdir mysql
# cd mysql
# mkdir data
# mkdir conf
3.启动命令(携带配置启动,挂载数据文件位置)
# docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -v /root/mysql/conf:/etc/mysql/conf.d -v /root/mysql/data:/var/lib/mysql mysql
[root@wangcai mysql]# docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -v /root/mysql/conf:/etc/mysql/conf.d -v /root/mysql/data:/var/lib/mysql mysql
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
501b36367dcfc9953a7e804aa1a70c8c387bcb3e543ab70351a82b6a0534685c
3.查看本地是否有挂在的目录
# cd /root/mysql/data
# ls
[root@wangcai data]# ls
auto.cnf binlog.index client-cert.pem '#ib_16384_1.dblwr' ib_logfile0 '#innodb_temp' performance_schema server-cert.pem undo_001
binlog.000001 ca-key.pem client-key.pem ib_buffer_pool ib_logfile1 mysql private_key.pem server-key.pem undo_002
binlog.000002 ca.pem '#ib_16384_0.dblwr' ibdata1 ibtmp1 mysql.ibd public_key.pem sys
DockerFile
基本指令