Getting started with SpringBoot Docker, SpringBoot Docker installation

Getting started with SpringBoot Docker, SpringBoot Docker installation

 

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

©Copyright Sweet Potato Yao April 2, 2018

http://fanshuyao.iteye.com/

 

1. Install Docker

1. Check the Linux version

uname -r

 Docker requires that the Linux system version is at least 3.10, as follows:

uname -r
  3.10.0-327.el7.x86_64

 

2. Install Docker

yum install docker

 

The installation process needs to enter y to confirm the installation

when it appears

Complete!

Indicates that the Docker installation was successful!

 

3. Start Docker

systemctl start docker

 

4. Check the Docker version

docker -v

 The result is as follows:

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

or use:

docker version

 The result is as follows:

[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. Set Docker to start up

systemctl enable docker

 The result is as follows:

[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. Stop Docker

systemctl stop docker

 

Second, Docker use

1. Search Mysql

docker search mysql

 

2. Download mysql

docker pull mysql

 The default is to download the latest version. If you want to download the specified version, you can add a tag. The tag refers to the version number.

 

To view the version, you can go to docker Hub: https://hub.docker.com/r/library/mysql/tags/

The command is as follows:

docker pull mysql:tag

 Such as:

docker pull mysql:5.5

 

3. Replace the Dock Hub

Official website address: https://hub.docker.com/explore/

There will be a timeout when using docker Hub to download directly, as follows:

net/http: TLS handshake timeout

 So you need to replace the mirror as follows (change to Ali's mirror):

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

 then restart docker

systemctl restart docker

 An error occurs at this point:

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

 The reason is that the image is modified, resulting in an incorrect format of the /etc/docker/daemon.json file, followed by a comma

 

Check out the daemon.json file:

vi /etc/docker/daemon.json

 The contents of the file are as follows:

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

 There is a comma after it, which needs to be deleted and modified to

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

 Save and exit, restart docker

systemctl restart docker

 Then go to get mysql 5.5 version

docker pull mysql:5.5

 

4. View the mirrors that exist in the system

docker images

 The result is as follows:

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

 

3. Running the image (container use)

1. Run an image component, that is, create a docker window, which can run multiple

docker run --name xxxx -d component name: version number (Tag)

 --name: means renaming (-- is two horizontal bars, which cannot be seen here)

-d: means running in the background

Such as running a tomcat:

docker run --name mytomcat -d tomcat:8.5

 

2. View running containers

docker ps

 

3. View all containers, including running and paused containers

docker ps -a

 

4. Stop the running container

docker stop container ID

 or

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月2日

http://fanshuyao.iteye.com/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326078503&siteId=291194637