SpringBoot Docker入门,SpringBoot Docker安装
================================
©Copyright 蕃薯耀 2018年4月8日
http://www.cnblogs.com/fanshuyao/
一、安装Docker
1、查看Linux版本
- uname -r
Docker要求Linux系统的版本不低于3.10,如下:
- uname -r
- 3.10.0-327.el7.x86_64
2、安装Docker
- yum install docker
安装过程需要输入 y 确定安装
当出现
Complete!
表示Docker安装成功!
3、启动Docker
- systemctl start docker
4、查看Docker版本
- docker -v
结果如下:
- [root@localhost ~]# docker -v
- Docker version 1.13.1, build 774336d/1.13.1
或者使用:
- docker version
结果如下:
- [root@localhost ~]# docker version
- Client:
- Version: 1.13.1
- API version: 1.26
- Package version: <unknown>
- Go version: go1.8.3
- Git commit: 774336d/1.13.1
- Built: Wed Mar 7 17:06:16 2018
- OS/Arch: linux/amd64
- Server:
- Version: 1.13.1
- API version: 1.26 (minimum version 1.12)
- Package version: <unknown>
- Go version: go1.8.3
- Git commit: 774336d/1.13.1
- Built: Wed Mar 7 17:06:16 2018
- OS/Arch: linux/amd64
- Experimental: false
5、设置Docker开机启动
- systemctl enable docker
结果如下:
- [root@localhost ~]# systemctl enable docker
- Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/
- systemd/system/docker.service.
6、停止Docker
- systemctl stop docker
二、Docker使用
1、搜索Mysql
- docker search mysql
2、下载mysql
- docker pull mysql
默认是下载最新版本,如果想下载指定版本的,可以加上tag,tag指的就是版本号,
查看版本可以到docker Hub:https://hub.docker.com/r/library/mysql/tags/
命令如下:
- docker pull mysql:tag
如:
- docker pull mysql:5.5
3、更换Dock Hub
官网地址:https://hub.docker.com/explore/
使用docker Hub直接下载会出现超时,如下:
- net/http: TLS handshake timeout
所以需要更换镜像,如下(更改为阿里的镜像):
- curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s https://04c5r1cy.mirror.aliyuncs.com
然后重启docker
- systemctl restart docker
此时会发生错误:
- Job for docker.service failed because the control process exited with error code. See "systemctl statu
- s docker.service" and "journalctl -xe" for details.
原因是修改了镜像,造成/etc/docker/daemon.json文件的格式不正确,后面多了一个逗号
查看daemon.json文件:
- vi /etc/docker/daemon.json
文件内容如下:
- {"registry-mirrors": ["https://04c5r1cy.mirror.aliyuncs.com"],}
后面多了一个逗号,需要删除,修改为
- {"registry-mirrors": ["https://04c5r1cy.mirror.aliyuncs.com"]}
保存退出,重启docker
- systemctl restart docker
然后再去获取mysql 5.5版本
- docker pull mysql:5.5
4、查看系统存在的镜像
- docker images
结果如下:
- [root@localhost ~]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- docker.io/mysql 5.5 0da48351c371 2 weeks ago 205 MB
三、运行镜像(容器使用)
1、运行一个镜像组件,即创建一个docker窗口,可以运行多个
- docker run --name xxxx -d 组件名:版本号(Tag)
--name:表示重命名(--是两横杠,这里看不出来)
-d:表示后台运行
如运行一个tomcat:
- docker run --name mytomcat -d tomcat:8.5
2、查看运行中的容器
- docker ps
3、查看所有容器,包括运行的和暂停的容器
- docker ps -a
4、停止运行中的容器
- docker stop 容器ID
或
- docker stop 容器names
最好使用容器ID
5、重新开始运行暂定的容器
- docker start 容器ID
暂停的容器ID通过docker ps -a 查找
6、删除容器
- docker rm -f 容器ID
结果如下:
- [root@localhost ~]# docker rm -f a9c2f22a4b50
- a9c2f22a4b50
7、启动一个有端口映射的容器(Tomcat)
- docker run -d -p 8888:8080 tomcat
-d:表示后台运行
-p:表示端口映射,前面的端口为虚拟机的端口,后面的端口表示tomcat的端口,表示将虚拟机的8888端口映射到tomcat的8080端口,当访问192.168.1.166:8888就可以访问tomcat
启动的结果如下:
- [root@localhost ~]# docker run --name tomcat8 -d -p 8080:8080 tomcat:8.5
- b91a31986a63f82340c588272a334c164de571fb4201d628bad3418f55d7f20b
- [root@localhost ~]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 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有没有启动成功。
注意:
如果访问不了,可能是因为防火墙的原因!!!
查看防火墙状态:
- service firewall status
关闭防火墙
- service firewall stop
8、查看docker日志
- docker logs 容器ID
9、其它:
使用
- docker --help
查看其它命令,如下:
- [root@localhost ~]# docker --help
- Usage: docker COMMAND
- A self-sufficient runtime for containers
- Options:
- --config string Location of client config files (default "/root/.docker")
- -D, --debug Enable debug mode
- --help Print usage
- -H, --host list Daemon socket(s) to connect to (default [])
- -l, --log-level string Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info")
- --tls Use TLS; implied by --tlsverify
- --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
- --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
- --tlskey string Path to TLS key file (default "/root/.docker/key.pem")
- --tlsverify Use TLS and verify the remote
- -v, --version Print version information and quit
- Management Commands:
- container Manage containers
- image Manage images
- network Manage networks
- node Manage Swarm nodes
- plugin Manage plugins
- secret Manage Docker secrets
- service Manage services
- stack Manage Docker stacks
- swarm Manage Swarm
- system Manage Docker
- volume Manage volumes
- Commands:
- attach Attach to a running container
- build Build an image from a Dockerfile
- commit Create a new image from a container's changes
- cp Copy files/folders between a container and the local filesystem
- create Create a new container
- diff Inspect changes on a container's filesystem
- events Get real time events from the server
- exec Run a command in a running container
- export Export a container's filesystem as a tar archive
- history Show the history of an image
- images List images
- import Import the contents from a tarball to create a filesystem image
- info Display system-wide information
- inspect Return low-level information on Docker objects
- kill Kill one or more running containers
- load Load an image from a tar archive or STDIN
- login Log in to a Docker registry
- logout Log out from a Docker registry
- logs Fetch the logs of a container
- pause Pause all processes within one or more containers
- port List port mappings or a specific mapping for the container
- ps List containers
- pull Pull an image or a repository from a registry
- push Push an image or a repository to a registry
- rename Rename a container
- restart Restart one or more containers
- rm Remove one or more containers
- rmi Remove one or more images
- run Run a command in a new container
- save Save one or more images to a tar archive (streamed to STDOUT by default)
- search Search the Docker Hub for images
- start Start one or more stopped containers
- stats Display a live stream of container(s) resource usage statistics
- stop Stop one or more running containers
- tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
- top Display the running processes of a container
- unpause Unpause all processes within one or more containers
- update Update configuration of one or more containers
- version Show the Docker version information
- wait Block until one or more containers stop, then print their exit codes
- Run 'docker COMMAND --help' for more information on a command.
================================
©Copyright 蕃薯耀 2018年4月8日
http://www.cnblogs.com/fanshuyao/