docker build报错Error response from daemon: Unknown instruction的解决
一 错误现象
在上手实践操作docker的过程中,通过docker file 将一个springboot的Java应用,打成docker image的过程,遇到下述错误:
[root@centos-master t]# docker build . -t java-demo-redis:v1.1
Sending build context to Docker daemon 27.3 MB
Error response from daemon: Unknown instruction: ENTRYPOINT["JAVA","-JAR","/APP.JAR"]
[root@centos-master t]#
二 环境说明
OS版本:
[root@centos-master t]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@centos-master t]#
docker 版本:
[root@centos-master t]# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version: docker-1.13.1-208.git7d71120.el7_9.x86_64
Go version: go1.10.3
Git commit: 7d71120/1.13.1
Built: Mon Jun 7 15:36:09 2021
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Package version: docker-1.13.1-208.git7d71120.el7_9.x86_64
Go version: go1.10.3
Git commit: 7d71120/1.13.1
Built: Mon Jun 7 15:36:09 2021
OS/Arch: linux/amd64
Experimental: false
[root@centos-master t]#
文件路径信息:
[root@centos-master t]# pwd
/root/t
[root@centos-master t]# ll
总用量 8
-rw-r--r-- 1 root root 217 11月 9 11:22 Dockerfile
drwxr-xr-x 2 root root 4096 11月 9 11:09 target
[root@centos-master t]# ll target/
总用量 26660
-rw-r--r-- 1 root root 27297536 11月 9 10:53 demo-docker-redis-0.0.1-SNAPSHOT.jar
[root@centos-master t]#
Dockerfile:
[root@centos-master t]# cat Dockerfile
FROM openjdk:8-jdk-oracle
LABEL maintainer=huangwei
#将target路径下的所有jar 复制到Controller中的/app.jar
COPY target/*.jar /app.jar
#启动container中的/app.jar
ENTRYPOINT["java","-jar","/app.jar"]
[root@centos-master t]#
三 错误原因
错误原因,Dockerfile中,最后处,ENTRYPOINT 和执行命令[ xxxx],要预留1个空格出来。
[root@centos-master t]# cat Dockerfile
FROM openjdk:8-jdk-oracle
LABEL maintainer=huangwei
#将target路径下的所有jar 复制到Controller中的/app.jar
COPY target/*.jar /app.jar
#启动container中的/app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
[root@centos-master t]#
四构建成功
最后构建成功:
[root@centos-master t]# pwd
/root/t
[root@centos-master t]# ll
总用量 8
-rw-r--r-- 1 root root 217 11月 9 11:22 Dockerfile
drwxr-xr-x 2 root root 4096 11月 9 11:09 target
[root@centos-master t]# docker build -t java-demo-redis:v1.1 -f Dockerfile .
Sending build context to Docker daemon 27.3 MB
Step 1/4 : FROM openjdk:8-jdk-oracle
Trying to pull repository docker.io/library/openjdk ...
8-jdk-oracle: Pulling from docker.io/library/openjdk
0a6167eaa66c: Pull complete
9a88dabbf57e: Pull complete
e39d55b2d90c: Pull complete
Digest: sha256:791a4056fc9d3f7d4059e2a8b1ada19c9e90d54ce7ee700deccb73e21bdf9f73
Status: Downloaded newer image for docker.io/openjdk:8-jdk-oracle
---> 6cafe44c1f04
Step 2/4 : LABEL maintainer huangwei
---> Running in 74485a50bbbc
---> 9c9d5adbf382
Removing intermediate container 74485a50bbbc
Step 3/4 : COPY target/*.jar /app.jar
---> 046a4b84c703
Removing intermediate container ba1650547c6e
Step 4/4 : ENTRYPOINT java -jar /app.jar
---> Running in 494fc12d6ce7
---> 494be6b1bcbe
Removing intermediate container 494fc12d6ce7
Successfully built 494be6b1bcbe
[root@centos-master t]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
java-demo-redis v1.1 494be6b1bcbe 2 minutes ago 386 MB
new_index_nginx v1.0 786f3a72a365 42 hours ago 133 MB
renguzi/huangwei v1.1 786f3a72a365 42 hours ago 133 MB
renguzi/huangwei v1.2 786f3a72a365 42 hours ago 133 MB
docker.io/openjdk 8-jdk-oracle 6cafe44c1f04 5 days ago 359 MB
docker.io/redis latest 7faaec683238 3 weeks ago 113 MB
docker.io/nginx latest 87a94228f133 4 weeks ago 133 MB
docker.io/rancher/rancher v2.0.0 3141e5c66ee8 3 years ago 535 MB
[root@centos-master t]#
五启动container:
[root@centos-master t]# docker run -itd --name my-demo-java-redis -p 8081:8080 java-demo-redis:v1.1
696d926736d44c3a505b065f1e5cbfdac09c878aa55a382996e0465a06571e20
[root@centos-master t]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
696d926736d4 java-demo-redis:v1.1 "java -jar /app.jar" 3 seconds ago Up 2 seconds 0.0.0.0:8081->8080/tcp my-demo-java-redis
bba5f1482183 redis "docker-entrypoint..." 18 hours ago Up 17 hours 0.0.0.0:6399->6379/tcp myredis
b593dad555eb renguzi/huangwei:v1.2 "/docker-entrypoin..." 20 hours ago Up 20 hours 0.0.0.0:82->80/tcp n2
2dd108812224 renguzi/huangwei:v1.2 "/docker-entrypoin..." 24 hours ago Up 24 hours 0.0.0.0:81->80/tcp mount_nginx
62fe090e2c1c new_index_nginx:v1.0 "/docker-entrypoin..." 42 hours ago Up 42 hours 0.0.0.0:99->80/tcp new_index_ngxinx
6a41868cf3d6 nginx "/docker-entrypoin..." 3 days ago Up 3 days 0.0.0.0:88->80/tcp mynginx
58eca0394a3a rancher/rancher:v2.0.0 "rancher --http-li..." 6 days ago Up 6 days 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp clever_brown
[root@centos-master t]#