centos安装使用docker

1. 安装docker,最好centos版本7.x(不是可重装或参考网上6.5安装教程),linux内核3.1+(不是可升级内核),docker安装详细可参考菜鸟教程

(1)产看linux版本

[root@jalen demo-service-hi]# lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.4.1708 (Core) 
Release:	7.4.1708
Codename:	Core


(2)查看内核版本

[root@jalen demo-service-hi]# uname -r
3.10.0-693.2.2.el7.x86_64


(3)安装docker

[root@jalen demo-service-hi]# yum -y install docker


(4)关闭/启动docker,也可使用systemd操作

[root@jalen demo-service-hi]# service docker stop
Redirecting to /bin/systemctl stop docker.service
[root@jalen demo-service-hi]# service docker start
Redirecting to /bin/systemctl start docker.service




2. 以spring cloud项目为例,进入maven项目根目录

(1)打包镜像

[root@jalen ~]# cd /usr/local/jalen/tomcat/demo-eureka-server/
[root@jalen demo-eureka-server]# ls
demo-eureka-server.iml  mvnw  mvnw.cmd  pom.xml  src  target
[root@jalen demo-eureka-server]# mvn clean package docker:build


(2)如果服务器购自类似搬瓦工等国外运营商,无需加速;


(3)如果是国内阿里云等,需做docker加速处理,否则超慢,可从DaoCloud获取镜像,将镜像链接添加到 /etc/docker/daemon.json文件中





3. 查看当前打包好的docker镜像,这里我打了两个,jalen/*-*-*

[root@jalen demo-service-hi]# docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
jalen/demo-service-hi                  latest              8143462b6e72        10 seconds ago      203 MB
jalen/demo-eureka-server               latest              9ea3aae87063        2 minutes ago       208 MB
<none>                                 <none>              d27ae327e5be        55 minutes ago      208 MB
docker.io/frolvlad/alpine-oraclejdk8   slim                afe006594870        2 weeks ago         167 MB




4. 运行镜像,-p指后台运行

[root@jalen demo-eureka-server]# docker run -p 8761:8761 -t jalen/demo-eureka-server

[root@jalen demo-eureka-server]# docker run -p 8763:8763 -t jalen/demo-service-hi




5. 页面访问地址,47.98.242.28是我的阿里云地址,8761为服务注册中心,8763为一个服务实例

http://47.98.242.28:8761/
http://47.98.242.28:8763/hi?name=jalen




6. 查看当前服务器正在运行的docker镜像

[root@jalen demo-eureka-server]# docker ps
CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                    NAMES
6c8edaed2497        jalen/demo-service-hi      "java -Djava.secur..."   2 minutes ago       Up 2 minutes        0.0.0.0:8763->8763/tcp   jolly_visvesvaraya
0635e97ec951        jalen/demo-eureka-server   "java -Djava.secur..."   3 minutes ago       Up 3 minutes        0.0.0.0:8761->8761/tcp   dreamy_mcnulty




项目代码参考,可以使用7z打成tar.gz包到云上再执行以上操作

https://github.com/SincerelyUnique/spring-cloud-demo/tree/master/11docker%20deploy





6. 除以上方法外,还可以使用docker-compose命令部署,一次直接部署多个镜像

[root@jalen 12docker deploy compose]# docker-compose up
Creating network "12dockerdeploycompose_default" with the default driver
Creating 12dockerdeploycompose_eureka-server_1 ... done
Creating 12dockerdeploycompose_service-hi_1    ... done
Attaching to 12dockerdeploycompose_eureka-server_1, 12dockerdeploycompose_service-hi_1
eureka-server_1  | 2018-04-19 01:06:37.923  INFO 1 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@1376c05c: startup date [Thu Apr 19 01:06:37 GMT 2018]; root of context hierarchy
service-hi_1     | 2018-04-19 01:06:37.937  INFO 1 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@1376c05c: startup date [Thu Apr 19 01:06:37 GMT 2018]; root of context hierarchy
eureka-server_1  | 2018-04-19 01:06:40.394  INFO 1 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
service-hi_1     | 2018-04-19 01:06:40.508  INFO 1 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
service-hi_1     | 2018-04-19 01:06:40.972  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$7e4594e4] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
eureka-server_1  | 2018-04-19 01:06:40.985  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$7e4594e4] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
eureka-server_1  | 
eureka-server_1  |   .   ____          _            __ _ _
eureka-server_1  |  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
eureka-server_1  | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
eureka-server_1  |  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
eureka-server_1  |   '  |____| .__|_| |_|_| |_\__, | / / / /
eureka-server_1  |  =========|_|==============|___/=/_/_/_/
eureka-server_1  |  :: Spring Boot ::        (v1.5.2.RELEASE)
eureka-server_1  | 
eureka-server_1  | 2018-04-19 01:06:43.650  INFO 1 --- [           main] c.e.eureka.server.demo.DemoApplication   : No active profile set, falling back to default profiles: default
eureka-server_1  | 2018-04-19 01:06:43.752  INFO 1 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3a82f6ef: startup date [Thu Apr 19 01:06:43 GMT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@1376c05c
service-hi_1     | 
service-hi_1     |   .   ____          _            __ _ _
service-hi_1     |  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
service-hi_1     | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
service-hi_1     |  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
service-hi_1     |   '  |____| .__|_| |_|_| |_\__, | / / / /
service-hi_1     |  =========|_|==============|___/=/_/_/_/
service-hi_1     |  :: Spring Boot ::        (v1.5.2.RELEASE)
service-hi_1     | 
service-hi_1     | 2018-04-19 01:06:43.991  INFO 1 --- [           main] c.e.service.hi.demo.DemoApplication      : No active profile set, falling back to default profiles: default
service-hi_1     | 2018-04-19 01:06:44.102  INFO 1 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6d00a15d: startup date [Thu Apr 19 01:06:44 GMT 20




7. 如果想要使用docker-compose后台部署,可以

[root@jalen 12docker deploy compose]# docker-compose up -d



项目代码参考

https://github.com/SincerelyUnique/spring-cloud-demo/tree/master/12docker%20deploy%20compose


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jalen备忘录

谢谢~~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值