Servi de nombreuses pages et forums et n'a pas trouvé de solution. J'ai le simple conteneur de docker avec le fichier exécutable .sh. Lorsque je le construis et l'exécute à partir de Windows, tout va bien. Essayez maintenant de le construire à partir d'Ubuntu 18.04 avec la version 19.03.5 de Docker.
Pour la reconstruction, utilisez le script .sh que j'exécute en tant que bash install.sh
go build -o main.sh ./main
docker stop stats
docker container rm stats
docker image rm stats
docker build -t stats .
docker run --name stats -p 8080:8080 stats
Mon Dockerfile est:
FROM alpine:3.10.1
ARG appPath="app"
RUN mkdir /app/
COPY main.sh /app/main.sh
RUN chmod +x /app/main.sh
COPY resources /app/resources
RUN apk add --no-cache bash
WORKDIR /app
EXPOSE 8080
CMD /bin/bash -c 'ls' && /app/main.sh dev
L'appel de sortie 'install' est le suivant:
bash install.sh
stats
stats
Untagged: stats:latest
Sending build context to Docker daemon 38.98MB
Step 1/10 : FROM alpine:3.10.1
---> b7b28af77ffe
Step 2/10 : ARG appPath="app"
---> Using cache
---> 08baa7336701
Step 3/10 : RUN mkdir /app/
---> Using cache
---> fb9870e78322
Step 4/10 : COPY main.sh /app/main.sh
---> Using cache
---> 79bf713855e3
Step 5/10 : RUN chmod +x /app/main.sh
---> Using cache
---> 88bf70f9c6ec
Step 6/10 : COPY resources /app/resources
---> Using cache
---> 2ebf95627a9e
Step 7/10 : RUN apk add --no-cache bash
---> Using cache
---> 39cd823e7f2f
Step 8/10 : WORKDIR /app
---> Using cache
---> 37e6fcea2d65
Step 9/10 : EXPOSE 8080
---> Using cache
---> 4250094c65f6
Step 10/10 : CMD /bin/bash -c 'ls' && /app/main.sh dev
---> Using cache
---> ed41a1efb15b
Successfully built ed41a1efb15b
Successfully tagged stats:latest
main.sh
resources
/bin/sh: /app/main.sh: not found
Je ne comprends pas ce qui ne va pas. main.sh est là. Si j'essaie d'exécuter, CMD /bin/bash -c 'ls' && bash main.sh dev
recevez main.sh: main.sh: cannot execute binary file
.
Quel est le problème et comment puis-je y remédier?
UPD:
Le fichier a été renommé comme étant binaire et ne devrait pas avoir .sh à la fin.
Et réessayé avec ce qui suit:
install.sh
#!/bin/bash
go build -o myapp ./main
docker stop stats
docker container rm stats
docker image rm stats
docker build -t stats .
docker run --name stats -p 8080:8080 stats
Dockerfile
FROM alpine:3.10.1
RUN mkdir /app/
COPY myapp /app/myapp
RUN chmod +x /app/myapp
COPY resources /app/resources
RUN apk add --no-cache bash
WORKDIR /app
EXPOSE 8080
CMD /bin/bash -c 'ls' && ./myapp dev
La sortie était la suivante:
....
Step 9/9 : CMD /bin/bash -c 'ls' && ./myapp dev
---> Running in 52fc24d26747
Removing intermediate container 52fc24d26747
---> 8d4f415e6dcd
Successfully built 8d4f415e6dcd
Successfully tagged stats:latest
myapp
resources
/bin/sh: ./myapp: not found
Essayé /app/myapp
, ./myapp
et cela ne fonctionne pas.
Je suppose que le message d'erreur est trompeur et que le vrai problème est qu'une bibliothèque ou un autre composant d'exécution Go est absent de votre image Docker. Essayez de créer votre application de manière statique (ce qui signifie que tout ce dont elle a besoin sera regroupé dans le binaire).
CGO_ENABLED=0 go build -o myapp ./main
(Et oui, ne l'appelez pas main.sh
si ce n'est pas un script shell. Unix s'en fiche, mais vous déroutez vos lecteurs humains. Et en fait, ne l'appelez pas ainsi même si c'est le cas. Vous n'avez pas besoin de savoir s'il grep
s'agit d'un binaire, d'un script shell ou d'un programme Python; la même convention a du sens pour vos propres outils.)
Cet article est collecté sur Internet, veuillez indiquer la source lors de la réimpression.
En cas d'infraction, veuillez [email protected] Supprimer.
laisse moi dire quelques mots