docker项目实战

目录

1、使用mysql:5.6和 owncloud 镜像,构建一个个人网盘。

1)拉取mysql:5.6和owncloud镜像

2)后台运行容器

 3)通过ip:端口的方式访问owncloud

2、安装搭建私有仓库 Harbor

1)首先准备所需包

2)安装harbor

3)使用ip地址访问

4)推送镜像

3、编写Dockerfile制作Web应用系统nginx镜像,生成镜像nginx:v1.1,并推送其到私有仓库。

1)制作镜像

2)推送镜像

4、Dockerfile快速搭建自己专属的LAMP环境,生成镜像lamp:v1.1,并推送到私有仓库。


1、使用mysql:5.6和 owncloud 镜像,构建一个个人网盘。

1)拉取mysql:5.6和owncloud镜像

[root@localhost ~]# docker pull mysql:5.6
[root@localhost ~]# docker pull owncloud

2)后台运行容器

[root@localhost ~]# docker run -itd --name mysql1 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6 [root@localhost ~]# docker run -itd -p5900:80 --name owncloud1 owncloud:latest

 3)通过ip:端口的方式访问owncloud

跟据向导信息完成部署

#上传文件成功即可开始使用

2、安装搭建私有仓库 Harbor

1)首先准备所需包

[root@localhost ~]# ls
harbor-offline-installer-v2.8.4.tgz docker-compose-linux-x86_64

2)安装harbor

mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose #检查docker-compose版本
docker-compose --versiontar xf harbor-offline-installer-v2.8.4.tgz -C /usr/local/
cd /usr/local/
cd harbor/#备份配置文件
cp harbor.yml.tmpl harbor.yml#修改配置文件(按需修改)
vim harbor.yml#安装启动harbor
./install.sh 
[+] Running 10/10✔ Network harbor_harbor        Created  0.0s ✔ Container harbor-log         Started  0.3s ✔ Container registry           Started  0.6s ✔ Container harbor-portal      Started  0.6s ✔ Container registryctl        Started  0.4s ✔ Container redis              Started  0.7s ✔ Container harbor-db          Started  0.8s ✔ Container harbor-core        Started  0.9s ✔ Container harbor-jobservice  Started  1.4s ✔ Container nginx              Started  1.4s 
✔ ----Harbor has been installed and started successfully.----

3)使用ip地址访问

#因为使用的80端口映射,所以直接访问ip地址
[root@master harbor]# docker ps
CONTAINER ID   IMAGE                                COMMAND                   CREATED          STATUS                    PORTS                                       NAMES
ad357892e9b7   goharbor/nginx-photon:v2.8.4         "nginx -g 'daemon of…"   14 minutes ago   Up 14 minutes (healthy)   0.0.0.0:80->8080/tcp, :::80->8080/tcp       nginx

4)推送镜像

#命令行登录harbor
[root@master ~]# docker login harbor.com.cn
Username: admin   
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded#打标签
[root@master ~]# docker tag mysql:5.6 harbor.com.cn/own-cloud/mysql:5.6
#推送
[root@master ~]# docker push harbor.com.cn/own-cloud/mysql:5.6
The push refers to repository [harbor.com.cn/library/mysql]
7137327a7221: Pushed 
49a1ca1cd2b8: Pushed 
7c5a5c1986b1: Pushed 
eba393347f89: Pushed 
2612088e90f6: Pushed 
e3dce1c82d4e: Pushed 
7ea96a4e341b: Pushed 
4085e588967d: Pushed 
d414fdead0b9: Pushed 
2e1029557391: Pushed 
2b83e5699838: Pushed 
5.6: digest: sha256:897086d07d1efa876224b147397ea8d3147e61dd84dce963aace1d5e9dc2802d size: 2621#退出登录
[root@master ~]# docker logout
Removing login credentials for https://index.docker.io/v1/

3、编写Dockerfile制作Web应用系统nginx镜像,生成镜像nginx:v1.1,并推送其到私有仓库。

具体要求如下:
(1)基于centos基础镜像;
(2)指定作者信息;
(3)安装nginx服务,将提供的dest目录(提供默认主页index.html)传到镜像内,并将dest目录内的前端文件复制到nginx的工作目录;
(4)暴露80端口;
(5)设置服务自启动。
(6)验证镜像。

1)制作镜像

#创建默认主页
[root@master ~]# mkdir nginx
[root@master ~]# cd nginx/
[root@master nginx]# vim index.html
<h1>docker nginx build successful</h1>#编写Dockerfile文件(最好放在空目录)
[root@master ~]# mkdir /dockerfile/web -p
[root@master ~]# cd /dockerfile/web/
[root@master web]# vim Dockerfile#指定使用镜像及版本
FROM centos:7#标明作者和邮箱
MAINTAINER "test <test.1@139.com>"#下载wget配置epel源下载nginx
RUN yum install -y wget 
RUN wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
RUN yum install -y nginx#将提前写好的主页替换掉默认的
COPY index.html /usr/share/nginx/html/index.html#暴露80端口
EXPOSE 80/tcp#设置开机自启服务
CMD ["nginx", "-g", "daemon off;"]#构建nginx:v1.1镜像
[root@master nginx]# docker build -t nginx:v1.1 -f /dockerfile/web/Dockerfile .
[+] Building 42.0s (10/10) FINISHED                                                                      docker:default=> [internal] load build definition from Dockerfile                                                               0.0s=> => transferring dockerfile: 320B                                                                               0.0s=> [internal] load .dockerignore                                                                                  0.0s=> => transferring context: 2B                                                                                    0.0s=> [internal] load metadata for docker.io/library/centos:7                                                        0.0s=> CACHED [1/5] FROM docker.io/library/centos:7                                                                   0.0s=> [internal] load build context                                                                                  0.0s=> => transferring context: 77B                                                                                   0.0s=> [2/5] RUN yum install -y wget                                                                                 18.9s=> [3/5] RUN wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo                        0.7s=> [4/5] RUN yum install -y nginx                                                                                21.6s => [5/5] COPY index.html /usr/share/nginx/html/index.html                                                          0.0s => exporting to image                                                                                             0.7s => => exporting layers                                                                                            0.7s => => writing image sha256:c35cac64c3d272124c91e46fd52b9c9935fcb5686890b29241035d7474f03182                       0.0s => => naming to docker.io/library/nginx:v1.1                                                                      0.0s#查看成功构建的镜像
[root@master nginx]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
nginx        v1.1      c35cac64c3d2   4 minutes ago   684MB
centos       7         eeb6ee3f44bd   23 months ago   204MB#使用构建的镜像启动一个容器
[root@master ~]# docker run -d -p 3000:80 --name test1 nginx:v1.1 
b22cc4550e85e0bf4512467abfbbfb310c07d18246c78ad1f8e5909acec1176c
[root@master ~]# docker ps
CONTAINER ID   IMAGE        COMMAND                   CREATED         STATUS         PORTS                                   NAMES
b22cc4550e85   nginx:v1.1   "nginx -g 'daemon of…"   4 seconds ago   Up 4 seconds   0.0.0.0:3000->80/tcp, :::3000->80/tcp   test1

2)推送镜像

#登录自己的dockerhub镜像仓库
[root@master ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: workl
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
#打包镜像
[root@master ~]# docker tag nginx:v1.1 workl/test1:my_nginx
#推送镜像
[root@master ~]# docker push workl/test1:my_nginx
The push refers to repository [docker.io/workl/test1]
fab04c3e6af6: Pushed 
c5cd136625a9: Pushed 
bac427254136: Pushed 
e7bdba266517: Pushed 
174f56854903: Pushed 


4、Dockerfile快速搭建自己专属的LAMP环境,生成镜像lamp:v1.1,并推送到私有仓库。

具体要求如下:
(1)基于centos:6基础镜像;
(2)指定作者信息;
(3)安装httpd、mysql、mysql-server、php、php-mysql、php-gd;
(4)暴露80和3306端口;
(5)设置服务自启动。
(6)验证镜像。

 [root@master dockerfile]# mkdir lamp
[root@master ~]# cd dockerfile/lamp/
[root@master lamp]# ls
Dockerfile
[root@master lamp]# vim Dockerfile#注意:宿主机使用的版本尽量与docker拉取的镜像版本一致
FROM centos:6
MAINTAINER "test <test.1@139.com>"RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo && sed -i 's|http://mirrors.aliyun.com/centos|https://mirrors.aliyun.com/centos-vault/centos|g' /etc/yum.repos.d/CentOS-Base.repo
RUN yum install -y wget && wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
COPY run.sh /run.sh
RUN chmod +x /run.sh
RUN yum install -y httpd mysql mysql-server php php-mysql php-gd
ADD wordpress-4.8-zh_CN.tar.gz /var/www/htmlEXPOSE 80 3306
CMD ["./run.sh"][root@master ~]# mkdir lamp
[root@master ~]# cd lamp/
[root@master lamp]# vim run.sh
#!/bin/bash
systemctl start mysql
sleep 3
mysql -e "create database wordpress;"
mysql -e "grant all privileges on *.* to 'root'@'%' identified by '123456';"
sleep 3
systemctl start httpd[root@master lamp]# chmod +x run.sh 
[root@master lamp]# ls
run.sh                                              wordpress-4.8-zh_CN.tar.gz[root@master lamp]# docker build -t lamp:v1.1 -f /dockerfile/lamp/Dockerfile .
[+] Building 31.1s (11/11) FINISHED                                                                      docker:default=> [internal] load build definition from Dockerfile                                                               0.0s=> => transferring dockerfile: 615B                                                                               0.0s=> [internal] load .dockerignore                                                                                  0.0s=> => transferring context: 2B                                                                                    0.0s=> [internal] load metadata for docker.io/library/centos:7                                                        0.0s=> [1/6] FROM docker.io/library/centos:7                                                                          0.0s=> [internal] load build context                                                                                  0.0s=> => transferring context: 76B                                                                                   0.0s=> CACHED [2/6] RUN yum install -y wget && wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epe  0.0s=> CACHED [3/6] COPY run.sh /run.sh                                                                               0.0s=> CACHED [4/6] RUN chmod +x /run.sh                                                                              0.0s=> [5/6] RUN yum install -y httpd mysql mysql-server php php-mysql php-gd                                        29.6s=> [6/6] ADD wordpress-4.8-zh_CN.tar.gz /var/www/html                                                             0.2s => exporting to image                                                                                             1.2s => => exporting layers                                                                                            1.2s => => writing image sha256:6197e9c54d05cf3f2aeda27ea570102d2a30d73f0f49b89f6817fc85e923468c                       0.0s => => naming to docker.io/library/lamp:v1.1                                                                       0.0s 
[root@master lamp]# docker images
REPOSITORY    TAG        IMAGE ID       CREATED          SIZE
lamp          v1.1       6197e9c54d05   15 seconds ago   823MB
nginx         v1.1       c35cac64c3d2   3 hours ago      684MB
workl/test1   my_nginx   c35cac64c3d2   3 hours ago      684MB
centos        6          5bf9684f4720   23 months ago    194MB
centos        7          eeb6ee3f44bd   23 months ago    204MB[root@master lamp]# docker run -itd --name test1 lamp:v1.1 /bin/bash
4f0a785b22fd7241ab777ff493e8537eb332444144bdb13b86d376016916fa7e
[root@master lamp]# docker ps
CONTAINER ID   IMAGE       COMMAND       CREATED          STATUS          PORTS              NAMES
4f0a785b22fd   lamp:v1.1   "/bin/bash"   16 seconds ago   Up 16 seconds   80/tcp, 3306/tcp   test1

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/88624.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【PLSQL】PLSQL基础

文章目录 一&#xff1a;记录类型1.语法2.代码实例 二&#xff1a;字符转换三&#xff1a;%TYPE和%ROWTYPE1.%TYPE2.%ROWTYPE 四&#xff1a;循环1.LOOP2.WHILE&#xff08;推荐&#xff09;3.数字式循环 五&#xff1a;游标1.游标定义及读取2.游标属性3.NO_DATA_FOUND和%NOTFO…

CSS 滚动容器与固定 Tabbar 自适应的几种方式

问题 容器高度使用 px 定高时&#xff0c;随着页面高度发生变化&#xff0c;组件展示的数量不能最大化的铺满&#xff0c;导致出现底部留白。容器高度使用 vw 定高时&#xff0c;随着页面宽度发生变化&#xff0c;组件展示的数量不能最大化的铺满&#xff0c;导致出现底部留白…

三、pikachu之文件上传

文章目录 1、文件上传概述2、客户端检测2.1 客户端检测原理及绕过方法2.2 实际操作之client check 3、服务端检测3.1 MIME type3.3.1 检测原理3.3.2 绕过方法3.3.3 实际操作之MIME type 3.2 文件内容检测3.2.1 检测原理3.2.2 绕过方式3.2.3 实际操作之getimagesize() 3.3 其他服…

MySQL binlog的几种日志录入格式以及区别

&#x1f3c6;作者简介&#xff0c;黑夜开发者&#xff0c;CSDN领军人物&#xff0c;全栈领域优质创作者✌&#xff0c;CSDN博客专家&#xff0c;阿里云社区专家博主&#xff0c;2023年6月CSDN上海赛道top4。 &#x1f3c6;数年电商行业从业经验&#xff0c;历任核心研发工程师…

L1-044 稳赢(Python实现) 测试点全过

题目 大家应该都会玩“锤子剪刀布”的游戏&#xff1a;两人同时给出手势&#xff0c;胜负规则如图所示&#xff1a; 现要求你编写一个稳赢不输的程序&#xff0c;根据对方的出招&#xff0c;给出对应的赢招。但是&#xff01;为了不让对方输得太惨&#xff0c;你需要每隔K次就…

STM32之17.PWM脉冲宽度调制

一LED0脉冲宽度调制在TIM14_CHI&#xff0c;先将LED&#xff08;PF9&#xff09;代码配置为AF推挽输出模式&#xff0c;将PF9引脚连接到TIM14&#xff0c; #include <stm32f4xx.h>static GPIO_InitTypeDef GPIO_InitStruct;void Led_init(void) {//打开端口F的硬件时钟&a…

Android——基本控件(下)(十九)

1. 菜单&#xff1a;Menu 1.1 知识点 &#xff08;1&#xff09;掌握Android中菜单的使用&#xff1b; &#xff08;2&#xff09;掌握选项菜单&#xff08;OptionsMenu&#xff09;的使用&#xff1b; &#xff08;3&#xff09;掌握上下文菜单&#xff08;ContextMenu&am…

运维Shell脚本小试牛刀(二)

运维Shell脚本小试牛刀(一) 运维Shell脚本小试牛刀(二) 一: if---else.....fi 条件判断演示 [rootwww shelldic]# cat checkpass.sh #!/bin/bash - # # # # FILE: checkpass.sh # USAGE: ./checkpass.sh # DESCRI…

简易虚拟培训系统-UI控件的应用3

目录 Button组件的组成 Button组件方法1-在Button组件中设置OnClick()回调 Button组件方法2-在脚本中添加Button类的监听 上一篇使用了文件流读取硬盘数据并显示在Text组件中&#xff0c;本篇增加使用按钮来控制显示哪一篇文字信息。 Button组件的组成 1. 新建Button&#…

智慧能源助力绿色发展

居民生活是碳排放的重要贡献源&#xff0c;作为居民生活的主要场所&#xff0c;社区是低碳城市建设的重要空间载体。推动低碳社区建设&#xff0c;逐渐打造低碳生活方式&#xff0c;是低碳社会建设的重要内容之一。智慧新能源公共设施助力碳中和&#xff0c;用于各社区改造&…

68、使用aws官方的demo和配置aws服务,进行视频流上传播放

基本思想:参考官方视频,进行了配置aws,测试了视频推流,rtsp和mp4格式的视频貌似有问题,待调研和解决 第一步:1) 进入aws的网站,然后进入ioT Core 2)先配置 Thing types & Thing,选择香港的节点,然后AWS ioT--->Manage---> Thing type 然后输入名字,创建Th…

前端工程化

前后端混合开发 前后端分离开发 接口文档&#xff1a;一个业务功能就是一个接口 开发某个功能的流程&#xff1a; 需求分析&#xff0c;接口定义&#xff08;API接口文档&#xff09;&#xff0c;前后端并行开发&#xff08;遵守规范&#xff09;&#xff0c;测试&#xff…