(1) 实现一个自定义的web容器服务
---------------------------------------准备工作------------------------------------------
1、创建mynginx目录并进入目录创建Dockerfile文件
2、获取配置文件内容
2.1由于我之前已经拉过nginx和mysql的镜像,所以它们直接在本地
2.2运行nginx容器
2.3进入容器
2.4获取配置文件default.conf的内容
2.5将端口号改为4399和root路径改为自己的本地文件路径并保存
2.6创建一个简易的html文件(index.html)
3、编写Dockerfile文件
------------------------------------------------------开始正式构建----------------------------------------------------------
4、构建nginx镜像
docker build -t mynginx:v1 .
5、运行一个容器
$ docker run --name my_nginx -p 8080:4399 -d nginx
---------------------------------------------------------------验证结果---------------------------------------------------------------
(2) 实现一个自定义的数据库容器服务
1、创建自定义的存放目录mymysql
2、进入目录创建Dockerfile文件
3、编写Dockerfile文件
3.1setup.sh
3.2data.sql
3.3privileges.sql
4、构建mysql镜像
docker build -t mysql:v1 .
4.1执行docker images查看镜像
4.2启动容器
5、查看配置信息
[ { "Id": "sha256:8e8c6f8dc9dfbd7090bb1565f902110ef828b8cb032f4b8bd00aefbf8bf9113f", "RepoTags": [ "mysql:latest" ], "RepoDigests": [ "mysql@sha256:fc77c7d56aa74239e659d0bb4aa3268f476c595521f932e90aca530687709598" ], "Parent": "", "Comment": "", "Created": "2020-04-17T16:57:06.578502642Z", "Container": "02c8a1605f71984c8ea67a8fab60e457bf2f07b3a343ed18a1e0335c80c9eab6", "ContainerConfig": { "Hostname": "02c8a1605f71", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "3306/tcp": {}, "33060/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "GOSU_VERSION=1.12", "MYSQL_MAJOR=8.0", "MYSQL_VERSION=8.0.19-1debian10" ], "Cmd": [ "/bin/sh", "-c", "#(nop) ", "CMD ["mysqld"]" ], "ArgsEscaped": true, "Image": "sha256:aafa1e5b6b2df3563b5103b4acaace8094b715c9d785daf6a64085a8c7cf2ad7", "Volumes": { "/var/lib/mysql": {} }, "WorkingDir": "", "Entrypoint": [ "docker-entrypoint.sh" ], "OnBuild": null, "Labels": {} }, "DockerVersion": "18.09.7", "Author": "", "Config": { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "3306/tcp": {}, "33060/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "GOSU_VERSION=1.12", "MYSQL_MAJOR=8.0", "MYSQL_VERSION=8.0.19-1debian10" ], "Cmd": [ "mysqld" ], "ArgsEscaped": true, "Image": "sha256:aafa1e5b6b2df3563b5103b4acaace8094b715c9d785daf6a64085a8c7cf2ad7", "Volumes": { "/var/lib/mysql": {} }, "WorkingDir": "", "Entrypoint": [ "docker-entrypoint.sh" ], "OnBuild": null, "Labels": null }, "Architecture": "amd64", "Os": "linux", "Size": 546299331, "VirtualSize": 546299331, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/190fb85f29360e64df81e1966e35885360f068ba90e56db7306d177574566cae/diff:/var/lib/docker/overlay2/be1986d8b0b2d52f6dfb6b181e2d9a093a0d049468ddd6b4f91f41f3a911922f/diff:/var/lib/docker/overlay2/5d0d0f708f6ed438738adbed4e3953e91cbf4d784621763a1f2f588fcf262c9b/diff:/var/lib/docker/overlay2/c2c38646e08e98827fb7ba4222b30067168698b2efef06110afbdd24bf7be435/diff:/var/lib/docker/overlay2/8774f21d3de967c5e4e10a63676ee063a5fd2343a2770628cd83bb931f7de698/diff:/var/lib/docker/overlay2/fb69536ad4eedd0deabd9cde44ec89ff28ce6bf3307fa23acec482c0c222e7e0/diff:/var/lib/docker/overlay2/5ec01f49eaf705a3affeab7a97af532e4c62b5149c1012c0fd51c5d7591deece/diff:/var/lib/docker/overlay2/922c2ceaede46a48b352b4dde50ca234ac33543bd19e595b1cbde9738ec22d81/diff:/var/lib/docker/overlay2/800410e275d29fccfd3604d60a8577868023b18663169ffc43ead598fc2ad37d/diff:/var/lib/docker/overlay2/b22d5987a98f2fd53c065df1317f3d97b0dc98580998ac8285b279a459a1fd89/diff:/var/lib/docker/overlay2/8cf51cc5a21f11aeeeeb5d65f61d9ca39e1482fb0f743bd965e4fddd32bdc794/diff", "MergedDir": "/var/lib/docker/overlay2/314668b1217d69a91402f7975726631536fcd80a040f682578b9dae0607ef949/merged", "UpperDir": "/var/lib/docker/overlay2/314668b1217d69a91402f7975726631536fcd80a040f682578b9dae0607ef949/diff", "WorkDir": "/var/lib/docker/overlay2/314668b1217d69a91402f7975726631536fcd80a040f682578b9dae0607ef949/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:b60e5c3bcef2f42ec42648b3acf7baf6de1fa780ca16d9180f3b4a3f266fe7bc", "sha256:746ef614d66131a14736cc3e9b10a4c33bfe246bee826802af3d1c55f4787faf", "sha256:478bf6a73d060e527285d1cb3428a61b068ac4e23d3b44aae944ccf6a5438ff5", "sha256:246ad53299e099d265c24fe63a0c8564838a58f1408e1bf0915aa969704f005f", "sha256:f2b1703888edba3399b82f9ebdd1c98e729f05b6cb5fd8c5d8f85af0b73589ad", "sha256:c73d9f519696cf503017bd93185b0df9e4c97539d9bffb7e861e1f419e074032", "sha256:c4a52d4531b78de76b169a5312c023fc6bb856b1603eeb2748ac3e8622999273", "sha256:53e783b27a6d65725dcbde7dca30fd191830207c2427a6691515c6f14a111f78", "sha256:ef2a52de3c1a84d8b724098453eaa3c1c1d818fefe66cb03fa5e3a806a759df8", "sha256:73734f0984252c1ae65c0c7efeeb3923ba3879e8fd1f22ab858a90d758ef2359", "sha256:ace58d0dd227634d234244a5fab6cf03dca139097862c310ceae51ac120aab1e", "sha256:fe80e859fd88eadcac800804791ad84e8ec8db8bca61cfc4d718b784e488b75c" ] }, "Metadata": { "LastTagTime": "0001-01-01T00:00:00Z" } } ]
6、进入mysql,验证信息
6.1查看内容
小结:又是忙忙碌碌的一周实验,主要知道了如何利用Dockfile自定义镜像,中间也碰到过类似于系统文件已满(/dev/sda1)无法写入的问题,由于忘记截屏,所以没有展示。我就去追踪文件然后删除了一些缓存和日志文件。还有就是后面的MYSQL镜像制作那块要用到Mysql的语句知识,当时学的也忘得差不多了,就当是又看了一遍。