系统综合实验第二次作业

(1) 实现一个自定义的web容器服务

  • 推荐apache或nginx,要求标明镜像作者信息,安装必要的工具以方便维护;设定你自己的web存放目录,安全起见,请将默认的监听端口80更改为你自定义的端口,并且声明暴露的端口,容器启动时,能直接进入web代码的存放目录。

1.拉取镜像

2.通过镜像打开容器

3.查看初始端口和文件存储位置

4.编写dockerfile并编写相关文件用于更改端口以及所指向的html文件

mkdir Dockerfile
gedit lhw.html
gedit new.conf


5.创建更改后的镜像并验证更改后的情况

查看端口号

进入网址查看

(2) 实现一个自定义的数据库容器服务

  • 可选择Mysql,Mariadb等,要求标明镜像作者信息,为了方便维护,需要能够查看容器内的配置信息,包括但不限于网络、应用配置文件等。在环境变量中设置好数据库的root密码且不允许空密码登录,创建一个测试数据库,指定用户名和密码。

1.拉取mysql:5.7镜像


这一步建议先自己弄下阿里云镜像加速器,不然拉取过程会是漫长的等待还可能没有结果。。。说多了都是泪。

2.编写相关文件

mkdir mysql
gedit Dockerfile

gedit privileges.sql

gedit schema.sql

gedit setup.sh

3.创建镜像

运行容器

查看容器id

4.连接mysql并查看表

5.查看配置信息

[
    {
        "Id": "fd8762b8d8c216878a93d6d74e03a96ca5f6795a8c2e7046012988059990633e",
        "Created": "2020-04-25T09:23:48.845997289Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "sh",
            "/mysql/setup.sh"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 3194,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2020-04-25T09:23:50.122502071Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:b3a6201c205d378a89ea3c6f5daf7367347443305caa1a3ea55e1e30cdae91ab",
        "ResolvConfPath": "/var/lib/docker/containers/fd8762b8d8c216878a93d6d74e03a96ca5f6795a8c2e7046012988059990633e/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/fd8762b8d8c216878a93d6d74e03a96ca5f6795a8c2e7046012988059990633e/hostname",
        "HostsPath": "/var/lib/docker/containers/fd8762b8d8c216878a93d6d74e03a96ca5f6795a8c2e7046012988059990633e/hosts",
        "LogPath": "/var/lib/docker/containers/fd8762b8d8c216878a93d6d74e03a96ca5f6795a8c2e7046012988059990633e/fd8762b8d8c216878a93d6d74e03a96ca5f6795a8c2e7046012988059990633e-json.log",
        "Name": "/lhw",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "3306/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "3336"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Capabilities": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/7af8f819ab3c8f4c3fac98a049bcb9e8f56b863133aaa9d40bdfbb6639627148-init/diff:/var/lib/docker/overlay2/ade84627c6cd152084d698d8e66b08d1799fda53451cdda5cf2a0af4c81d09a9/diff:/var/lib/docker/overlay2/266d1076d6a0a567ff32d379a09f8e4ef48af48d1e0017b1ea633ac38502ccd5/diff:/var/lib/docker/overlay2/8cbbcbd6436fc943ea161464614239763c8aeba7f1c245ec863405edd80cb116/diff:/var/lib/docker/overlay2/04bfee12bb13409920f3a74f43e8aabf0f8b8986fa0e30e5cce17c809e64c63f/diff:/var/lib/docker/overlay2/2c6a1c5390286ea0bd4f226f3f0ad7b19fda817e599131dc7aafbe12c8c76cc2/diff:/var/lib/docker/overlay2/d2c92436df9b36b832afb7e81899ac59a1a27c835f110f3787cbd7e295feb6b3/diff:/var/lib/docker/overlay2/fa7bb8cbfd20d42cae4a895b460b06f3c12a4da1f2e3f88a5326f5308d780f7b/diff:/var/lib/docker/overlay2/0993558f45e4e106cea40356abe9f72ad680798155f0cd025a0c5e5e172cb558/diff:/var/lib/docker/overlay2/96c34c7985b4550070167ca7b562b723a979eda94e6f9aee08fd6825a46add3d/diff:/var/lib/docker/overlay2/839d49cb3ef1a83581eacb79dd33e087da3be09ff41c350cb55f5ed84c7f90a4/diff:/var/lib/docker/overlay2/9dc05e9a0f8a83ba66a314042f23968ad5c2ae16cd54a79cced82b91574e648a/diff:/var/lib/docker/overlay2/2d9a2ed48f9a89695a1937203346e494e1b807cd6d0ca1f95b905b966c687e04/diff:/var/lib/docker/overlay2/74f6e20d78ec4343b8965a2d283f9d9850b07c795e9907237aa8d3d2899d8b1e/diff:/var/lib/docker/overlay2/83bd3b2fd31a6a6a1ef36b8d137ef01e5ace3d58b6deed5c93f9ba5a98f76435/diff",
                "MergedDir": "/var/lib/docker/overlay2/7af8f819ab3c8f4c3fac98a049bcb9e8f56b863133aaa9d40bdfbb6639627148/merged",
                "UpperDir": "/var/lib/docker/overlay2/7af8f819ab3c8f4c3fac98a049bcb9e8f56b863133aaa9d40bdfbb6639627148/diff",
                "WorkDir": "/var/lib/docker/overlay2/7af8f819ab3c8f4c3fac98a049bcb9e8f56b863133aaa9d40bdfbb6639627148/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "volume",
                "Name": "b6a9f80823e0027ed971915a5c388ab4d8c66a0f5d37871109cf78b85dc57d37",
                "Source": "/var/lib/docker/volumes/b6a9f80823e0027ed971915a5c388ab4d8c66a0f5d37871109cf78b85dc57d37/_data",
                "Destination": "/var/lib/mysql",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "fd8762b8d8c2",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3306/tcp": {},
                "33060/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "MYSQL_ROOT_PASSWORD=123456",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "GOSU_VERSION=1.12",
                "MYSQL_MAJOR=5.7",
                "MYSQL_VERSION=5.7.29-1debian10",
                "MYSQL_ALLOW_EMPTY_PASSWORD=no"
            ],
            "Cmd": [
                "sh",
                "/mysql/setup.sh"
            ],
            "Image": "ms:lhw",
            "Volumes": {
                "/var/lib/mysql": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "7532188404a1dd1ef757eb708a9f4457c9c4cd984c9f4164fe5cf2984a62453c",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "3306/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "3336"
                    }
                ],
                "33060/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/7532188404a1",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "50bebbe74d9149e8c2500bf106b131e73ae2c6528ab0687c465876493c923359",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "ff8dc1d96c06253110e96171f76e5897e7ca225814c6099747a1a0b15bec28f2",
                    "EndpointID": "50bebbe74d9149e8c2500bf106b131e73ae2c6528ab0687c465876493c923359",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
posted @ 2020-04-24 15:16  牧分丶  阅读(295)  评论(0编辑  收藏  举报