SpringBoot application deployment to Docker

Configuring TCP remote connections

Why To configure this, because the use of docker-maven-plugin plug-default connection to localhost: docker on 2375. However: 1 to set before our Docker is not local, the implementation of the order to pack environment variables [ DOCKER_HOST = tcp: // <host> : 2375 ]; 2 Docker default tcp remote connection is closed, so we want to open.

Method One : Before we configure Ali cloud images when a new file daemon.json, now have to use this. It is to configure [ "hosts": [ "tcp: //0.0.0.0: 2375", "unix: ///var/run/docker.sock"] ]

Vim / etc / Docker / daemon.json 

# add the following, application specific address of its slightly 
{ 
  " Registry-Mirrors " : [ " HTTPS: //****.mirror.aliyuncs.com " ],
   " the hosts " : [ " tcp: //0.0.0.0: 2375 " , " UNIX: ///var/run/docker.sock " ] 
} 

# to restart the service 
systemctl daemon - reload 
systemctl restart Docker

Then open the firewall port 2375

[root@localhost admin]# firewall-cmd --zone=public --add-port=2375/tcp --permanent
success
[root@localhost admin]# systemctl restart firewalld

Test on whether access can be accessed in a browser, you can also curl in a virtual machine

If a virtual machine

[root@localhost admin]# curl localhost:2375
{"message":"page not found"}

Method Two :

[root@localhost admin]# vim /lib/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target rhel-push-plugin.socket registries.service
Wants=docker-storage-setup.service
Requires=docker-cleanup.timer

[Service]
Type=notify
NotifyAccess=all
EnvironmentFile=-/run/containers/registries.conf
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current \
          --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
          --default-runtime=docker-runc \
          --exec-opt native.cgroupdriver=systemd \
          --userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
          --init-path=/usr/libexec/docker/docker-init-current \
          --seccomp-profile=/etc/docker/seccomp.json \
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY \
          $REGISTRIES
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
KillMode=process

[Install]
WantedBy=multi-user.target

The last new red shown below wherein ExecStart

ExecStart=/usr/bin/dockerd-current \
          --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
          --default-runtime=docker-runc \
          --exec-opt native.cgroupdriver=systemd \
          --userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
          --init-path=/usr/libexec/docker/docker-init-current \
          --seccomp-profile=/etc/docker/seccomp.json \
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY \
          $REGISTRIES \
          -H unix:///var/run/docker.sock \
          -H tcp://0.0.0.0:2375

Then restart the service, you can still meet the needs of

# Restart the service 
systemctl daemon - reload 
systemctl restart Docker

Configure private warehouse

Go look at the configuration file

[root@localhost admin]# vim /etc/docker/daemon.json
# 在最后加上仓库配置
{
  "registry-mirrors": ["https://****.mirror.aliyuncs.com","http://hub-mirror.c.163.com"],
  "hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"],
  "insecure-registries":["192.168.192.128:443"]
}

 

Then download the image registry, start, I was the registry 5000 container port mapping to the host port 443, and you are free

[root@localhost admin]# docker pull registry
Using default tag: latest
Trying to pull repository docker.io/library/registry ... 
latest: Pulling from docker.io/library/registry
c87736221ed0: Pull complete 
1cc8e0bb44df: Pull complete 
54d33bcb37f5: Pull complete 
e8afc091c171: Pull complete 
b4541f6d3db6: Pull complete 
Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146
Status: Downloaded newer image for docker.io/registry:latest
[root@localhost admin]# docker run -d -p 443:5000 registry
b56713ddca3f4b5903cc456002624a6cd6a6b3b79b8a542b873c461ed31b1b3b

Remember to open firewall ports, refer to the above

[Put on all data and files are deleted after docker mirror removed, so take a local directory on the host to mount directories inside the vessel registry, after deleting registry files and container still ensure data is not lost]

Nothing but first create a directory on the host, and then start the registry when using the -v parameter to be mapped. Similar to the following:

Into the interior of the vessel registry, see the directory in which it

[root@localhost admin]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                   NAMES
b56713ddca3f        registry            "/entrypoint.sh /e..."   36 minutes ago      Up 21 minutes       0.0.0.0:443->5000/tcp   confident_
[root@localhost admin]# docker exec -it b56713ddca3f sh
/ # find / -name registry
/bin/registry
/etc/docker/registry
find: /proc/scsi: Permission denied
find: /sys/firmware: Permission denied
/var/lib/registry
/var/lib/registry/docker/registry

It can be seen mount  var / lib / registry directory, so:

Stop # container 
[root @ localhost ADMIN] # Docker STOP b56713ddca3f 
b56713ddca3f 
# delete container 
[root @ localhost ADMIN] # Docker RM b56713ddca3f 
b56713ddca3f 

# Create the host directory 
mkdir / usr / docker_registry_data 
# launch container 
Docker RUN -d -p 443 : 5000 -v / usr / docker_registry_data: / var / lib / registry registry

 

New Construction

Pom configuration file

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.2.0 </Version > 
                < the Configuration > 
                    <-! Docker required to push the image name to the host name and port warehouse as a prefix. For example, my-image to be pushed registry.example.com, the mirror to be marked as registry.example.com/my-image -> 
                    < imageName > 192.168.192.128:443/hello </ imageName > 
                    <-! Base image -> 
                    < baseImage > Java </ baseImage > 
                    < the entryPoint > [ "Java", "-jar", "/${project.build.finalName}.jar"] </ the entryPoint > 
                    <-! Copy-Service The '
                    resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                    <forceTags>true</forceTags>
                    <imageTags>
                        <imageTag>latest</ ImageTag>
                    </imageTags>
                </configuration>
            </plugin>
        </plugins>
    </build>

Then build, configure docker address, and then execute build command

SET DOCKER_HOST=tcp://192.168.192.128:2375
mvn clean package -Dmaven.test.skip=true docker:build -DpushImageTag

Back to the server to view mirror

Boot image

Browser access

 The first push above, the output will be a lot of things, but after a push would not, as follows:

Mirror:

 

Guess you like

Origin www.cnblogs.com/LUA123/p/11418922.html
Recommended