官方Docker Hub
https://hub.docker.com/
1、创建Repository
2、构建容器镜像
2.1、创建Dockerfile
FROM java:8
MAINTAINER itmrl
LABEL name="helloworld" version="1.0.0" author="itmrl"
COPY helloworld.jar helloworld.jar
EXPOSE 8080
CMD ["java","-jar","-Dfile.encoding=UTF-8","-Xms1024m","-Xmx1024m","helloworld.jar"]
2.2、构建镜像
[root@localhost test_dockerfile]# docker build -t itmrl/my-public-repo:1.0.0 .
Sending build context to Docker daemon 16.3MB
Step 1/6 : FROM java:8
---> d23bdf5b1b1b
Step 2/6 : MAINTAINER itmrl
---> Using cache
---> 120755b80993
Step 3/6 : LABEL name="helloworld" version="1.0.0" author="itmrl"
---> Using cache
---> abb2d50ac587
Step 4/6 : COPY helloworld.jar helloworld.jar
---> Using cache
---> e32226c676eb
Step 5/6 : EXPOSE 8080
---> Using cache
---> 8cfe98171a1e
Step 6/6 : CMD ["java","-jar","-Dfile.encoding=UTF-8","-Xms1024m","-Xmx1024m","helloworld.jar"]
---> Using cache
---> 4a97d3158956
Successfully built 4a97d3158956
Successfully tagged itmrl/my-public-repo:1.0.0
2.3、查看镜像
[root@localhost test_dockerfile]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
itmrl/my-public-repo 1.0.0 4a97d3158956 About an hour ago 659MB
2.4、创建容器
[root@localhost test_dockerfile]# docker run itmrl/my-public-repo:1.0.0
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.5.RELEASE)
2021-02-26 12:38:48.180 INFO 1 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on 141ac6fb329c with PID 1 (/helloworld.jar started by root in /)
2021-02-26 12:38:48.190 INFO 1 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2021-02-26 12:38:48.295 INFO 1 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@b065c63: startup date [Fri Feb 26 12:38:48 UTC 2021]; root of context hierarchy
2021-02-26 12:38:49.732 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2.5、将本地镜像推送到Docker Hub
[root@localhost test_dockerfile]# docker push itmrl/my-public-repo:1.0.0
The push refers to repository [docker.io/itmrl/my-public-repo]
7ecd0eab9c73: Preparing
35c20f26d188: Preparing
c3fe59dd9556: Preparing
6ed1a81ba5b6: Preparing
a3483ce177ce: Preparing
ce6c8756685b: Waiting
30339f20ced0: Waiting
0eb22bfb707d: Waiting
a2ae92ffcd29: Waiting
denied: requested access to the resource is denied
提示错误:denied: requested access to the resource is denied。在推送之前首先需要登录到Docker Hub
[root@localhost test_dockerfile]# 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: itmrl
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@localhost test_dockerfile]# docker push itmrl/my-public-repo:1.0.0
官方Docker Hub速度很慢,推送会经常会卡住