docker镜像和仓库管理练习

目录

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

二.安装搭建私有仓库Harbor

三.编写Dockerfile制作Web应用系统nginx镜像,生成镜像nginx:v1.1,并推送其到私有仓库,以下为具体要求:

四.Dockerfile快速搭建自己专属的LAMP环境,生成镜像lamp:v1.1,并推送到私有仓库,以下为具体要求:


 

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

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

[root@localhost ~]# docker pull owncloud

[root@localhost ~]# docker run -itd --name mydb --env MYSQL_ROOT_PASSWORD=SLB123 mysql:5.6

[root@localhost ~]# docker run -itd --name myweb -p 80:80 --link mydb:mydb owncloud

使用IP进行访问,用admin+运行容器时设置的密码登录 

docker镜像和仓库管理练习_第1张图片

docker镜像和仓库管理练习_第2张图片

二.安装搭建私有仓库Harbor

[root@localhost ~]# cd /usr/local/

[root@localhost local]# rz -E
rz waiting to receive.
[root@localhost local]# ll
total 651916
drwxr-xr-x. 2 root root         6 Apr 11  2018 bin
-rw-r--r--  1 root root  59383631 Aug 20 15:59 docker-compose-linux-x86_64
drwxr-xr-x. 2 root root         6 Apr 11  2018 etc
drwxr-xr-x. 2 root root         6 Apr 11  2018 games
-rw-r--r--  1 root root 608175520 Aug 20 16:01 harbor-offline-installer-v2.8.4.tgz
drwxr-xr-x. 2 root root         6 Apr 11  2018 include
drwxr-xr-x. 2 root root         6 Apr 11  2018 lib
drwxr-xr-x. 2 root root         6 Apr 11  2018 lib64
drwxr-xr-x. 2 root root         6 Apr 11  2018 libexec
drwxr-xr-x. 2 root root         6 Apr 11  2018 sbin
drwxr-xr-x. 5 root root        49 Jul 23 08:59 share
drwxr-xr-x. 2 root root         6 Apr 11  2018 src

[root@localhost local]# mv docker-compose-linux-x86_64 ./bin/docker-compose

[root@localhost local]# chmod +x /usr/local/bin/docker-compose

[root@localhost local]# docker-compose version
Docker Compose version v2.20.3

[root@localhost local]# tar -xf harbor-offline-installer-v2.8.4.tgz
[root@localhost harbor]# ll
total 597536
-rw-r--r-- 1 root root      3639 Aug 15 17:53 common.sh
-rw-r--r-- 1 root root 611834153 Aug 15 17:54 harbor.v2.8.4.tar.gz
-rw-r--r-- 1 root root     12499 Aug 15 17:53 harbor.yml.tmpl
-rwxr-xr-x 1 root root      2725 Aug 15 17:53 install.sh
-rw-r--r-- 1 root root     11347 Aug 15 17:53 LICENSE
-rwxr-xr-x 1 root root      1881 Aug 15 17:53 prepare

[root@localhost harbor]# cp harbor.yml.tmpl harbor.yml
[root@localhost harbor]# hostname
harborslb.com
[root@localhost harbor]# vim harbor.yml 

更改hostname和端口,注释https加密访问部分的内容,下方的password后面用于登录 

docker镜像和仓库管理练习_第3张图片

 

[root@localhost harbor]# ./install.sh 
√----Harbor has been installed and started successfully.----
[root@localhost harbor]# docker-compose ls
NAME                STATUS              CONFIG FILES
harbor              running(9)          /usr/local/harbor/docker-compose.yml

docker镜像和仓库管理练习_第4张图片

docker镜像和仓库管理练习_第5张图片 

三.编写Dockerfile制作Web应用系统nginx镜像,生成镜像nginx:v1.1,并推送其到私有仓库,以下为具体要求:

(1)基于centos基础镜像

(2)指定作者信息

(3)安装nginx服务,将提供的dest目录(提供默认主页index.html)传到镜像内,并将dest目录内的前端文件复制到nginx的工作目录

(4)暴露80端口

(5)设置服务自启动

(6)验证镜像

[root@harborslb centos]# vim /etc/docker/daemon.json
{
"registry-mirrors":["https://docker.mirrors.ustc.edu.cn"],
"insecure-registries":["192.168.2.190:8080"]
}

[root@localhost centos]# ll
total 1056
drwxr-xr-x 2 root root      24 Aug 24 14:21 dest
-rw-r--r-- 1 root root     162 Aug 24 14:21 Dockerfile
-rw-r--r-- 1 root root 1073322 Aug  9 19:20 nginx-1.22.0.tar.gz

[root@localhost centos]# vim Dockerfile
FROM centos
MAINTAINER "sulibao "
ADD nginx-1.22.0.tar.gz /centos
COPY dest /usr/share/nginx/html
EXPOSE 80
CMD ["nginx","-g","daemon off;"]

[root@localhost centos]# docker build -t nginx:v1.1 .
[+] Building 41.7s (8/8) FINISHED                                    docker:default
 => [internal] load build definition from Dockerfile                           0.0s
 => => transferring dockerfile: 201B                                           0.0s
 => [internal] load .dockerignore                                              0.0s
 => => transferring context: 2B                                                0.0s
 => [internal] load metadata for docker.io/library/centos:latest               1.1s
 => [1/3] FROM docker.io/library/centos@sha256:a27fd8080b517143cbbbab9dfb7c8  40.0s
 => => resolve docker.io/library/centos@sha256:a27fd8080b517143cbbbab9dfb7c85  0.0s
 => => sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd 762B / 762B  0.0s
 => => sha256:a1801b843b1bfaf77c501e7a6d3f709401a1e0c83863037fa3a 529B / 529B  0.0s
 => => sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c5 2.14kB / 2.14kB  0.0s
 => => sha256:a1d0c75327776413fa0db9ed3adcdbadedc95a662eb1 83.52MB / 83.52MB  35.3s
 => => extracting sha256:a1d0c75327776413fa0db9ed3adcdbadedc95a662eb1d360dad8  4.5s
 => [internal] load build context                                              0.0s
 => => transferring context: 1.07MB                                            0.0s
 => [2/3] ADD nginx-1.22.0.tar.gz /centos                                      0.5s
 => [3/3] COPY dest /usr/share/nginx/html                                      0.0s
 => exporting to image                                                         0.0s
 => => exporting layers                                                        0.0s
 => => writing image sha256:7ae3a2d1a01c44857fa7946d9c4d83fb1b1d703ddbcebf4ed  0.0s
 => => naming to docker.io/library/nginx:v1.1                                  0.0s

[root@localhost centos]# docker tag nginx:v1.1 192.168.2.190:8080/nginx:v1.1

[root@harborslb centos]# docker login http://192.168.2.190:8080
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-store

Login Succeeded

[root@harborslb centos]# docker push 192.168.2.190:8080/nginx:v1.1

[root@harborslb centos]# docker pull 192.168.2.190:8080/nginx:v1.1

[root@harborslb centos]# docker images
REPOSITORY                      TAG       IMAGE ID       CREATED          SIZE
nginx                           v1.1      7ae3a2d1a01c   2 hours ago     238MB
goharbor/harbor-exporter        v2.8.4    b8d33e28ec68   8 days ago       97.7MB
goharbor/redis-photon           v2.8.4    7b7324d651ca   8 days ago       120MB
goharbor/trivy-adapter-photon   v2.8.4    91d8e9f0b21a   8 days ago       464MB
goharbor/notary-server-photon   v2.8.4    a46f91560454   8 days ago       113MB
goharbor/notary-signer-photon   v2.8.4    da66bd8d944b   8 days ago       110MB
goharbor/harbor-registryctl     v2.8.4    805b38ca6bee   8 days ago       141MB
goharbor/registry-photon        v2.8.4    756769e94123   8 days ago       79MB
goharbor/nginx-photon           v2.8.4    375018db778b   8 days ago       116MB
goharbor/harbor-log             v2.8.4    8a2045fb24d2   8 days ago       124MB
goharbor/harbor-jobservice      v2.8.4    97808fc10f64   8 days ago       141MB
goharbor/harbor-core            v2.8.4    c26fcd0714d8   8 days ago       164MB
goharbor/harbor-portal          v2.8.4    4a8b0205c0f9   8 days ago       124MB
goharbor/harbor-db              v2.8.4    5b8af16d7420   8 days ago       174MB
goharbor/prepare                v2.8.4    bdbf974d86ce   8 days ago       166MB
mysql                           5.6       dd3b2a5dcb48   20 months ago    303MB
owncloud                        latest    327bd201c5fb   4 years ago      618MB

[root@localhost lamp]# docker run --name mynginx -itd nginx:v1.1 
3037a148018a4bbfe88c18526eed75fd82333facbf296a99dd04467456ac4e94

四.Dockerfile快速搭建自己专属的LAMP环境,生成镜像lamp:v1.1,并推送到私有仓库,以下为具体要求:

(1)基于centos:6基础镜像

(2)指定作者信息

(3)安装hhttpd、mysql、mysql-server、php、php-mysql、php-gd

(4)暴露80和3306端口

(5)设置服务自启动

(6)验证镜像

[root@localhost lamp]# vim Dockerfile
FROM centos
MAINTAINER "sulibao "
RUN yum -y install httpd mysql mysql-server php php-mysql php-gd
EXPOSE 80 3306

[root@localhost lamp]# docker build -t lamp:v1.1 .
[+] Building 5.0s (6/6) FINISHED                                                        docker:default
 => [internal] load build definition from Dockerfile                                              0.0s
 => => transferring dockerfile: 199B                                                              0.0s
 => [internal] load .dockerignore                                                                 0.0s
 => => transferring context: 2B                                                                   0.0s
 => [internal] load metadata for docker.io/library/centos:7                                       3.7s
 => [1/2] FROM docker.io/library/centos:7@sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8  0.0s
 => CACHED [2/2] RUN yum -y install httpd mysql mysql-server php php-mysql php-gd                 0.0s
 => exporting to image                                                                            1.3s
 => => exporting layers                                                                           1.3s
 => => writing image sha256:27d9fbc1eb61eed01309bb6f987c2c041c6efefa1eb27b3318ea1ea18745ab99      0.0s
 => => naming to docker.io/library/lamp:v1.1                                                      0.0s

[root@localhost lamp]# docker push lamp:v1.1 192.168.2.190:8080/lamp:v1.1

[root@localhost lamp]# docker pull 192.168.2.190:8080/lamp:v1.1

[root@localhost lamp]# docker images
REPOSITORY                      TAG       IMAGE ID       CREATED         SIZE
lamp                            v1.1      27d9fbc1eb61   3 minutes ago   569MB
nginx                           v1.1      7ae3a2d1a01c   2 hours ago     238MB
goharbor/harbor-exporter        v2.8.4    b8d33e28ec68   8 days ago      97.7MB
goharbor/redis-photon           v2.8.4    7b7324d651ca   8 days ago      120MB
goharbor/trivy-adapter-photon   v2.8.4    91d8e9f0b21a   8 days ago      464MB
goharbor/notary-server-photon   v2.8.4    a46f91560454   8 days ago      113MB
goharbor/notary-signer-photon   v2.8.4    da66bd8d944b   8 days ago      110MB
goharbor/harbor-registryctl     v2.8.4    805b38ca6bee   8 days ago      141MB
goharbor/registry-photon        v2.8.4    756769e94123   8 days ago      79MB
goharbor/nginx-photon           v2.8.4    375018db778b   8 days ago      116MB
goharbor/harbor-log             v2.8.4    8a2045fb24d2   8 days ago      124MB
goharbor/harbor-jobservice      v2.8.4    97808fc10f64   8 days ago      141MB
goharbor/harbor-core            v2.8.4    c26fcd0714d8   8 days ago      164MB
goharbor/harbor-portal          v2.8.4    4a8b0205c0f9   8 days ago      124MB
goharbor/harbor-db              v2.8.4    5b8af16d7420   8 days ago      174MB
goharbor/prepare                v2.8.4    bdbf974d86ce   8 days ago      166MB
mysql                           5.6       dd3b2a5dcb48   20 months ago   303MB
owncloud                        latest    327bd201c5fb   4 years ago     618MB

[root@localhost lamp]# docker run --name mylamp -itd lamp:v1.1 
9ec40c703103b6dcea549b528028a3e46fb783bb84f0e93e91ef096b86d21e4b

你可能感兴趣的:(Linux,#,docker,docker,容器,运维,docker-compose,Dockerfile)