Docker的安装,使用

Docker的安装,使用,第1张

Docker的安装,使用 1.安装Docker
# yum install -y yum-utils device-mapper-persistent-data lvm2
# yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo

# yum list docker-ce --showduplicates | sort -r
> docker-ce.x86_64            3:20.10.9-3.el7                     docker-ce-stable
> docker-ce.x86_64            3:20.10.8-3.el7                     docker-ce-stable
> docker-ce.x86_64            3:20.10.7-3.el7                     docker-ce-stable
# yum install docker-ce-20.10.9-3.el7 -y
# systemctl start docker
# ps -ef | grep docker
> root      1724     1  4 09:29 ?        00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
2.通过插件(idea),实现自动部署

2.1.开启docker的远程访问

# vi /usr/lib/systemd/system/docker.service
# systemctl daemon-reload
# systemctl restart docker
# ps -ef | grep docker
> root      1910     1  0 01:33 ?        00:00:00 /usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

2.2.配置Dockerfile文件

# 基础镜像, 使用centos *** 作系统
FROM centos:7
# 发布者
MAINTAINER zhanghf 

# 在docker容器构建时创建文件夹
RUN mkdir /usr/local/java

# 将宿主机的文件拷贝到容器中的具体目录
# ADD, 拷贝后自动解压; COPY, 只做拷贝
# 宿主机上的文件路径是Dockerfile的相对路径
# 如果按目前的配置, 则需要在Dockerfile文件所在路径下拥有jdk-8u301-linux-x64.tar.gz压缩包
ADD jdk-8u301-linux-x64.tar.gz /usr/local/java

# 在容器中创建/usr/local/java/jdk1.8.0_301与/usr/local/java/jdk的软连接
RUN ln -s /usr/local/java/jdk1.8.0_301 /usr/local/java/jdk

# 配置jdk环境
ENV JAVA_HOME /usr/local/java/jdk
ENV JRE_HOME ${JAVA_HOME}/jre
ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib
ENV PATH ${JAVA_HOME}/bin:$PATH

# 系统编码
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

#声明一个挂载点, 容器内此路径会对应宿主机的某个文件夹
VOLUME /tmp

#应用构建成功后的jar文件被复制到镜像内, 名字也改成了dockerdemo.jar
ADD target/dockerdemo-1.0-SNAPSHOT.jar dockerdemo.jar

#启动容器时的进程
ENTRYPOINT ["java","-jar","/dockerdemo.jar"]

#暴露8080端口
EXPOSE 8080

2.3.新建docker远程连接

2.4.新建运行配置(edit configuration)

2.5.执行运行配置,服务器上查看进程(第一次执行会比较慢)

# ps -ef | grep docker
> root      2359  1910  0 01:54 ?        00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 18080 -container-ip 172.17.0.2 -container-port 8080
> root      2364  1910  0 01:54 ?        00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 18080 -container-ip 172.17.0.2 -container-port 8080
> root      2397  2378 22 01:54 pts/0    00:00:16 java -jar /dockerdemo.jar
3.docker私有仓库搭建,上传/下载/删除镜像
# docker pull registry
# docker run -d -v /edc/images/registry:/var/lib/registry -p 5000:5000 --restart=always --name xdp-registry -e REGISTRY_STORAGE_DELETE_ENABLED=true registry
# curl 127.0.0.1:5000/v2/_catalog
> {"repositories":[]}
# docker pull hyper/docker-registry-web
# docker run -d -p 28080:8080 --name registry-web --link xdp-registry -e REGISTRY_URL=http://34.80.201.81:5000/v2 hyper/docker-registry-web

# vi /etc/docker/daemon.json
# systemctl restart docker
# docker images
> REPOSITORY                  TAG       IMAGE ID       CREATED          SIZE
> dockerdemo                  latest    ea025b655710   19 minutes ago   630MB
> centos                      7         eeb6ee3f44bd   4 weeks ago      204MB
# docker tag dockerdemo 34.80.201.81:5000/zhanghf/dockerdemo
# docker push 34.80.201.81:5000/zhanghf/dockerdemo

# docker pull 34.80.201.81:5000/zhanghf/dockerdemo
# docker images
> REPOSITORY                             TAG       IMAGE ID       CREATED          SIZE
> 34.80.201.81:5000/zhanghf/dockerdemo   latest    ea025b655710   52 minutes ago   630MB
# docker run -d -p 18080:8080 --name dockerdemo 34.80.201.81:5000/zhanghf/dockerdemo
# docker exec -it b8c74bbfc2c9 /bin/bash

# curl 34.80.201.81:5000/v2/_catalog
> {"repositories":["zhanghf/dockerdemo"]}
# curl http://34.80.201.81:5000/v2/zhanghf/dockerdemo/tags/list
> {"name":"zhanghf/dockerdemo","tags":["latest"]}
# curl http://34.80.201.81:5000/v2/zhanghf/dockerdemo/manifests/latest

# curl --header "Accept:application/vnd.docker.distribution.manifest.v2+json" -I -XGET 34.80.201.81:5000/v2/zhanghf/dockerdemo/manifests/1.0
> HTTP/1.1 200 OK
> Content-Length: 1368
> Content-Type: application/vnd.docker.distribution.manifest.v2+json
> Docker-Content-Digest: sha256:f51929e67efbacea4bebf0b11cd56af6f00a1d8c00d4606dbd3b3c09b5c454bf
> Docker-Distribution-Api-Version: registry/2.0
> Etag: "sha256:f51929e67efbacea4bebf0b11cd56af6f00a1d8c00d4606dbd3b3c09b5c454bf"
> X-Content-Type-Options: nosniff
> Date: Wed, 20 Oct 2021 03:35:45 GMT
# curl -I -X DELETE "34.80.201.81:5000/v2/zhanghf/dockerdemo/manifests/sha256:f51929e67efbacea4bebf0b11cd56af6f00a1d8c00d4606dbd3b3c09b5c454bf"

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/3996207.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-22
下一篇 2022-10-22

发表评论

登录后才能评论

评论列表(0条)

保存