1、使用mysql:5.6和 owncloud 镜像,构建一个个人网盘。
[root@bogon ~]# docker pull mysql:5.6
[root@bogon ~]# docker pull owncloud
[root@bogon ~]# docker run -itd --name mysql --env MYSQL_ROOT_PASSWORD=123456 mysql:5.6
[root@bogon ~]# docker run -itd -p 80:80 --name owncloud --link mysql:mysql owncloud
2、安装搭建私有仓库 Harbor
[root@bogon ~]# mkdir /harbor
[root@bogon harbor]# curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose% Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 15.4M 100 15.4M 0 0 772k 0 0:00:20 0:00:20 --:--:-- 383k
[root@bogon harbor]# chmod +x /usr/local/bin/docker-compose
https://ghproxy.com/https://github.com/goharbor/harbor/releases/download/v2.5.3/harbor-offline-installer-v2.5.3.tgz 安装包国内地址
[root@bogon ~]# tar xf harbor-offline-installer-v2.5.3.tgz
[root@bogon ~]# cd harbor
[root@bogon harbor]# cp harbor.yml.tmpl harbor.yml
[root@bogon harbor]# vim harbor.yml
# Configuration file of Harbor# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: www.lsq.com# http related config
http:# port for http, default is 80. If https enabled, this port will redirect to https portport: 8080# https related config
https:# https port for harbor, default is 443#port: 443# The path of cert and key files for nginx# certificate: /your/certificate/path# private_key: /your/private/key/path# # Uncomment following will enable tls communication between all harbor components
# internal_tls:
# # set enabled to true means internal tls is enabled
# enabled: true
# # put your cert and key files on dir
# dir: /etc/harbor/tls/internal[root@bogon harbor]# ./install.sh
默认账号为admin、密码为Harbor12345
3、编写Dockerfile制作Web应用系统nginx镜像,生成镜像nginx:v1.1,并推送其到私有仓库。具体要求如下:
(1)基于centos基础镜像;
(2)指定作者信息;
(3)安装nginx服务,将提供的dest目录(提供默认主页index.html)传到镜像内,并将dest目录内的前端文件复制到nginx的工作目录;
(4)暴露80端口;
(5)设置服务自启动。
(6)验证镜像。
[root@bogon ~]# docker pull centos:7
[root@bogon ~]# cd /
[root@bogon /]# mkdir centos
[root@bogon /]# cd centos/
[root@bogon centos]# touch index.html
[root@bogon centos]# echo 'Welcon to Nginx' > index.html
[root@bogon centos]# vim Dockerfile
FROM centos:7
MAINTAINER "lsq <lsq@163.com>"
RUN yum install wget -y && cd /etc/yum.repos.d/ && rm -rf ./* && \wget -0 /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && \wget -0 /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/
EXPOSE 80
CMD ["/usr/sbin/nginx","-g","daemon off;"]
~
[root@bogon centos]# docker build -t nginx:v1 .
[root@bogon centos]# docker run -p 8090:80 --name ng nginx:v1
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@bogon ~]# mkdir lamp
[root@bogon ~]# cd lamp/
[root@bogon lamp]#docker pull centos:6
[root@bogon lamp]#wget -O /root/lamp/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
[root@bogon lamp]# vim Dockerfile
FROM centos:6
MAINTAINER "longsiqi <longsiqi@163.com>"
ADD CentOS-Base.repo /etc/yum.repos.d/
RUN yum install -y httpd mysql mysqL-server php php-mysqL php-gd && \yum clean all && yum makecache
EXPOSE 80
EXPOSE 3306
CMD ["sh", "-c", "service httpd start && service mysqld start && tail -f /var/log/httpd/access_log"]
[root@bogon lamp]# docker build -t lamp:v1.1 .
[root@bogon lamp]# docker run -p 8060:80 --name lp lamp:v1.1