SpringBoot Docker入门,SpringBoot Docker安装

SpringBoot Docker入门,SpringBoot Docker安装

================================

©Copyright 蕃薯耀 2018年4月8日

http://www.cnblogs.com/fanshuyao/

一、安装Docker

1、查看Linux版本

  1. uname -r

Docker要求Linux系统的版本不低于3.10,如下:

  1. uname -r
  2. 3.10.0-327.el7.x86_64

2、安装Docker

  1. yum install docker

安装过程需要输入 y 确定安装

当出现

Complete!

表示Docker安装成功!

3、启动Docker

  1. systemctl start docker

4、查看Docker版本

  1. docker -v

结果如下:

  1. [root@localhost ~]# docker -v
  2. Docker version 1.13.1, build 774336d/1.13.1

或者使用:

  1. docker version

结果如下:

  1. [root@localhost ~]# docker version
  2. Client:
  3. Version:         1.13.1
  4. API version:     1.26
  5. Package version: <unknown>
  6. Go version:      go1.8.3
  7. Git commit:      774336d/1.13.1
  8. Built:           Wed Mar  7 17:06:16 2018
  9. OS/Arch:         linux/amd64
  10. Server:
  11. Version:         1.13.1
  12. API version:     1.26 (minimum version 1.12)
  13. Package version: <unknown>
  14. Go version:      go1.8.3
  15. Git commit:      774336d/1.13.1
  16. Built:           Wed Mar  7 17:06:16 2018
  17. OS/Arch:         linux/amd64
  18. Experimental:    false

5、设置Docker开机启动

  1. systemctl enable docker

结果如下:

  1. [root@localhost ~]# systemctl enable docker
  2. Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/
  3. systemd/system/docker.service.

6、停止Docker

  1. systemctl stop docker

二、Docker使用

1、搜索Mysql

  1. docker search mysql

2、下载mysql

  1. docker pull mysql

默认是下载最新版本,如果想下载指定版本的,可以加上tag,tag指的就是版本号,

查看版本可以到docker Hub:https://hub.docker.com/r/library/mysql/tags/

命令如下:

  1. docker pull mysql:tag

如:

  1. docker pull mysql:5.5

3、更换Dock Hub

官网地址:https://hub.docker.com/explore/

使用docker Hub直接下载会出现超时,如下:

  1. net/http: TLS handshake timeout

所以需要更换镜像,如下(更改为阿里的镜像):

  1. curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s https://04c5r1cy.mirror.aliyuncs.com

然后重启docker

  1. systemctl restart docker

此时会发生错误:

  1. Job for docker.service failed because the control process exited with error code. See "systemctl statu
  2. s docker.service" and "journalctl -xe" for details.

原因是修改了镜像,造成/etc/docker/daemon.json文件的格式不正确,后面多了一个逗号

查看daemon.json文件:

  1. vi /etc/docker/daemon.json

文件内容如下:

  1. {"registry-mirrors": ["https://04c5r1cy.mirror.aliyuncs.com"],}

后面多了一个逗号,需要删除,修改为

  1. {"registry-mirrors": ["https://04c5r1cy.mirror.aliyuncs.com"]}

保存退出,重启docker

  1. systemctl restart docker

然后再去获取mysql 5.5版本

  1. docker pull mysql:5.5

4、查看系统存在的镜像

  1. docker images

结果如下:

  1. [root@localhost ~]# docker images
  2. REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
  3. docker.io/mysql     5.5                 0da48351c371        2 weeks ago         205 MB

三、运行镜像(容器使用)

1、运行一个镜像组件,即创建一个docker窗口,可以运行多个

  1. docker run --name xxxx -d 组件名:版本号(Tag)

--name:表示重命名(--是两横杠,这里看不出来)

-d:表示后台运行

如运行一个tomcat:

  1. docker run --name mytomcat -d tomcat:8.5

2、查看运行中的容器

  1. docker ps

 

3、查看所有容器,包括运行的和暂停的容器

  1. docker ps -a

4、停止运行中的容器

  1. docker stop 容器ID

  1. docker stop 容器names

 最好使用容器ID

5、重新开始运行暂定的容器

  1. docker start 容器ID

暂停的容器ID通过docker ps -a 查找

6、删除容器

  1. docker rm -f 容器ID

结果如下:

  1. [root@localhost ~]# docker rm -f a9c2f22a4b50
  2. a9c2f22a4b50

7、启动一个有端口映射的容器(Tomcat)

  1. docker run -d -p 8888:8080 tomcat

-d:表示后台运行

-p:表示端口映射,前面的端口为虚拟机的端口,后面的端口表示tomcat的端口,表示将虚拟机的8888端口映射到tomcat的8080端口,当访问192.168.1.166:8888就可以访问tomcat

启动的结果如下:

  1. [root@localhost ~]# docker run --name tomcat8 -d -p 8080:8080 tomcat:8.5
  2. b91a31986a63f82340c588272a334c164de571fb4201d628bad3418f55d7f20b
  3. [root@localhost ~]# docker ps
  4. CONTAINER ID  IMAGE       COMMAND           CREATED        STATUS        PORTS                    NAMES
  5. b91a31986a63  tomcat:8.5  "catalina.sh run" 12 seconds ago Up 8 second   0.0.0.0:8080->8080/tcp   tomcat8

通过浏览器访问:http://localhost:8080/来检查tomcat有没有启动成功。

注意:

如果访问不了,可能是因为防火墙的原因!!!

查看防火墙状态:

  1. service firewall status

关闭防火墙

  1. service firewall stop

8、查看docker日志

  1. docker logs 容器ID

9、其它:

使用

  1. docker --help

查看其它命令,如下:

  1. [root@localhost ~]# docker --help
  2. Usage:  docker COMMAND
  3. A self-sufficient runtime for containers
  4. Options:
  5. --config string      Location of client config files (default "/root/.docker")
  6. -D, --debug              Enable debug mode
  7. --help               Print usage
  8. -H, --host list          Daemon socket(s) to connect to (default [])
  9. -l, --log-level string   Set the logging level ("debug", "info", "warn", "error",                                 "fatal") (default "info")
  10. --tls                Use TLS; implied by --tlsverify
  11. --tlscacert string   Trust certs signed only by this CA (default                                              "/root/.docker/ca.pem")
  12. --tlscert string     Path to TLS certificate file (default                                                    "/root/.docker/cert.pem")
  13. --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
  14. --tlsverify          Use TLS and verify the remote
  15. -v, --version            Print version information and quit
  16. Management Commands:
  17. container   Manage containers
  18. image       Manage images
  19. network     Manage networks
  20. node        Manage Swarm nodes
  21. plugin      Manage plugins
  22. secret      Manage Docker secrets
  23. service     Manage services
  24. stack       Manage Docker stacks
  25. swarm       Manage Swarm
  26. system      Manage Docker
  27. volume      Manage volumes
  28. Commands:
  29. attach      Attach to a running container
  30. build       Build an image from a Dockerfile
  31. commit      Create a new image from a container's changes
  32. cp          Copy files/folders between a container and the local filesystem
  33. create      Create a new container
  34. diff        Inspect changes on a container's filesystem
  35. events      Get real time events from the server
  36. exec        Run a command in a running container
  37. export      Export a container's filesystem as a tar archive
  38. history     Show the history of an image
  39. images      List images
  40. import      Import the contents from a tarball to create a filesystem image
  41. info        Display system-wide information
  42. inspect     Return low-level information on Docker objects
  43. kill        Kill one or more running containers
  44. load        Load an image from a tar archive or STDIN
  45. login       Log in to a Docker registry
  46. logout      Log out from a Docker registry
  47. logs        Fetch the logs of a container
  48. pause       Pause all processes within one or more containers
  49. port        List port mappings or a specific mapping for the container
  50. ps          List containers
  51. pull        Pull an image or a repository from a registry
  52. push        Push an image or a repository to a registry
  53. rename      Rename a container
  54. restart     Restart one or more containers
  55. rm          Remove one or more containers
  56. rmi         Remove one or more images
  57. run         Run a command in a new container
  58. save        Save one or more images to a tar archive (streamed to STDOUT by default)
  59. search      Search the Docker Hub for images
  60. start       Start one or more stopped containers
  61. stats       Display a live stream of container(s) resource usage statistics
  62. stop        Stop one or more running containers
  63. tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  64. top         Display the running processes of a container
  65. unpause     Unpause all processes within one or more containers
  66. update      Update configuration of one or more containers
  67. version     Show the Docker version information
  68. wait        Block until one or more containers stop, then print their exit codes
  69. Run 'docker COMMAND --help' for more information on a command.

================================

©Copyright 蕃薯耀 2018年4月8日

http://www.cnblogs.com/fanshuyao/

上一篇:c# datatable 分组


下一篇:java springboot activemq 邮件短信微服务,解决国际化服务的国内外兼容性问题,含各服务商调研情况