idea集成docker

moonjerx
2023-11-30 / 0 评论 / 79 阅读 / 正在检测是否收录...

修改docker.service

vim /usr/lib/systemd/system/docker.service

修改ExecStart这一行,开启2375端口远程访问

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

说明: Intelli] IDEA通过2375端口远程连接到Linux系统中的Docker.
重载配置并重启docker服务

systemctl daemon-reload && systemctl restart docker

3、开放端口

firewall -cmd --zone=public --add-port=2375/tcp --permanent && firewall -cmd --reload

测试接口

curl http://192.168.3.100:2375/version

看到类似如下内容
lpkrnp38.png

[WARNING] No entry found in settings.xml for serverId=docker-mx, cannot configure authentication for that registry

出现这个警告是因为settings.xml文件没有配置镜像仓库登录账号密码信息

            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.2.2</version>
                <executions>
                    <execution>
                        <id>build-image</id>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                    <!--                    <execution>-->
                    <!--                        <id>tag-image</id>-->
                    <!--                        <phase>package</phase>-->
                    <!--                        <goals>-->
                    <!--                            <goal>tag</goal>-->
                    <!--                        </goals>-->
                    <!--                        <configuration>-->
                    <!--                            <image>${project.name}</image>-->
                    <!--                            <newName>1${project.name}</newName>-->
                    <!--                        </configuration>-->
                    <!--                    </execution>-->
                    <execution>
                        <id>push-image</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>push</goal>
                        </goals>
                        <configuration>
                            <imageName>${project.name}</imageName>
                            <imageTags>
                                <imageTag>v${project.version}</imageTag>
                            </imageTags>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <!--docker api地址,构建镜像是通过api调用在192.168.245.133上构建,并推送到registryUrl上-->
                    <dockerHost>${docker.remote.host}</dockerHost>
                    <buildArgs>
                        <appName>${project.build.finalName}</appName>
                    </buildArgs>
                    <serverId>docker-mx</serverId>
                    <!--私有仓库地址-->
                    <registryUrl>${docker.registry.url}</registryUrl>
                    <!--镜像名称,必须带仓库地址,否则只会push到docker.io-->
                    <imageName>${docker.registry.url}/${project.name}:v${project.version}</imageName>
                    <imageTags>
                        <imageTag>v${project.version}</imageTag>
                    </imageTags>
                    <!-- 指定dockerfile所在目录 -->
                    <!--<dockerDirectory>${project.build.directory}</dockerDirectory>-->
                    <!--<dockerDirectory>src/main/docker</dockerDirectory>-->
                    <!-- All resources will be copied to this directory before building the image. -->
                    <!--<buildDirectory>${project.basedir}</buildDirectory>-->
                    <!--是否推送镜像-->
                    <!--<pushImage>true</pushImage>-->
                    <!--推送后是否覆盖已存在的标签镜像-->
                    <forceTags>true</forceTags>
                    <!--资源,类似Dockerfile里的 ADD -->
                    <resources>
                        <resource>
                            <!--在生成的docker目录下,新建目录-->
                            <targetPath>/</targetPath>
                            <!--docker-build时生成docker目录位置-->
                            <directory>${project.build.directory}</directory>
                            <!--                            <directory>${project.build.directory}</directory>-->
                            <include>${project.build.finalName}.jar</include>
                            <filtering>true</filtering>
                        </resource>
                    </resources>
                    <!--基础镜像-->
                    <baseImage>openjdk:8-jdk-alpine</baseImage>
                    <runs>
                        <run>echo "App is: ${project.name}"</run>
                        <!--<run>mkdir /app</run>-->
                    </runs>
                    <workdir>/app</workdir>
                    <exposes>${profiles.port}</exposes>
                    <!--启动容器里执行的命令:注意这里的格式,格式不对,会运行不成功的-->
                    <!--<entryPoint>["java", "-version"]</entryPoint>-->
                    <entryPoint>["java", "-jar","/${project.build.finalName}.jar"]</entryPoint>
                </configuration>
            </plugin>

控制台提示报错

[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.2.2:build (default-cli) on project mxhello: Exception caught: java.io.IOException: Cannot run program "docker-credential-desktop": error=2, No such file or directory -> [Help 1]

lpmgm88d.png
credsStore 改成 credStore ,但是别重启本地docker,否则这一项配置会被清除

0

评论 (0)

取消

您的IP: