Result of .sh script RUN from Dockerfile is not saved to image










0















After RUN ["./run.sh"], a folder produced by run.sh is visible from inside the script but lost once Docker continues.



Expected behaviour:
I would like to have access to the public/ folder, which is generated by the run.sh script.



Dockerfile



 ...
RUN mkdir -p /opt/site
WORKDIR /opt/site
VOLUME /opt/site
COPY . .

RUN ["chmod", "+x", "./run.sh"]
RUN ["./run.sh"]
RUN pwd
RUN ls
RUN ls public

FROM nginx
COPY --from=build-stage /opt/site/public /usr/share/nginx/html


Script



 #!/usr/bin/env bash
rm -rf public/ node_modules/ node_modules/.bin/ package-lock.json yarn.lock
npm install
ls
touch newfile.txt
npm run build
ls


ls from inside the run.sh script after build. The public folder is present.



...
Generated public/sw.js, which will precache 6 files, totaling 197705 bytes.
info Done building in 44.842 sec
*ls*
Dockerfile
config
gatsby-config.js
gatsby-node.js
newfile.txt
node_modules
package-lock.json
package.json
postcss.config.js
public
run.sh
src
static
tailwind.css
tailwind.js


ls from inside the Dockerfile. The public folder is missing and trying to interact with it leads to failure.



Removing intermediate container 1692fb171673
---> 474d83267ccb
Step 10/14 : RUN pwd
---> Running in 7c351b151904
/opt/site
Removing intermediate container 7c351b151904
---> bae37da8b513
Step 11/14 : RUN ls
---> Running in 384daf575cae
Dockerfile
config
gatsby-config.js
gatsby-node.js
package-lock.json
package.json
postcss.config.js
run.sh
src
static
tailwind.css
tailwind.js
Removing intermediate container 384daf575cae
---> 1f6743a4adc1
Step 12/14 : RUN ls public
---> Running in 7af84c5d72a0
ls: cannot access public: No such file or directory
The command '/bin/sh -c ls public' returned a non-zero code: 2
ERROR: Job failed: exit code 2









share|improve this question
























  • i have added newfile.txt as a test for precisely this issue

    – Finn Frotscher
    Nov 13 '18 at 10:10











  • do you build it by using docker or docker-compose ?

    – malyy
    Nov 13 '18 at 10:44











  • It is run from a gitlab-ci.yml file. the command is docker build git.finnfrotscher.com/finnfrotscher/finnfrotschercom/blob/…

    – Finn Frotscher
    Nov 13 '18 at 10:50















0















After RUN ["./run.sh"], a folder produced by run.sh is visible from inside the script but lost once Docker continues.



Expected behaviour:
I would like to have access to the public/ folder, which is generated by the run.sh script.



Dockerfile



 ...
RUN mkdir -p /opt/site
WORKDIR /opt/site
VOLUME /opt/site
COPY . .

RUN ["chmod", "+x", "./run.sh"]
RUN ["./run.sh"]
RUN pwd
RUN ls
RUN ls public

FROM nginx
COPY --from=build-stage /opt/site/public /usr/share/nginx/html


Script



 #!/usr/bin/env bash
rm -rf public/ node_modules/ node_modules/.bin/ package-lock.json yarn.lock
npm install
ls
touch newfile.txt
npm run build
ls


ls from inside the run.sh script after build. The public folder is present.



...
Generated public/sw.js, which will precache 6 files, totaling 197705 bytes.
info Done building in 44.842 sec
*ls*
Dockerfile
config
gatsby-config.js
gatsby-node.js
newfile.txt
node_modules
package-lock.json
package.json
postcss.config.js
public
run.sh
src
static
tailwind.css
tailwind.js


ls from inside the Dockerfile. The public folder is missing and trying to interact with it leads to failure.



Removing intermediate container 1692fb171673
---> 474d83267ccb
Step 10/14 : RUN pwd
---> Running in 7c351b151904
/opt/site
Removing intermediate container 7c351b151904
---> bae37da8b513
Step 11/14 : RUN ls
---> Running in 384daf575cae
Dockerfile
config
gatsby-config.js
gatsby-node.js
package-lock.json
package.json
postcss.config.js
run.sh
src
static
tailwind.css
tailwind.js
Removing intermediate container 384daf575cae
---> 1f6743a4adc1
Step 12/14 : RUN ls public
---> Running in 7af84c5d72a0
ls: cannot access public: No such file or directory
The command '/bin/sh -c ls public' returned a non-zero code: 2
ERROR: Job failed: exit code 2









share|improve this question
























  • i have added newfile.txt as a test for precisely this issue

    – Finn Frotscher
    Nov 13 '18 at 10:10











  • do you build it by using docker or docker-compose ?

    – malyy
    Nov 13 '18 at 10:44











  • It is run from a gitlab-ci.yml file. the command is docker build git.finnfrotscher.com/finnfrotscher/finnfrotschercom/blob/…

    – Finn Frotscher
    Nov 13 '18 at 10:50













0












0








0








After RUN ["./run.sh"], a folder produced by run.sh is visible from inside the script but lost once Docker continues.



Expected behaviour:
I would like to have access to the public/ folder, which is generated by the run.sh script.



Dockerfile



 ...
RUN mkdir -p /opt/site
WORKDIR /opt/site
VOLUME /opt/site
COPY . .

RUN ["chmod", "+x", "./run.sh"]
RUN ["./run.sh"]
RUN pwd
RUN ls
RUN ls public

FROM nginx
COPY --from=build-stage /opt/site/public /usr/share/nginx/html


Script



 #!/usr/bin/env bash
rm -rf public/ node_modules/ node_modules/.bin/ package-lock.json yarn.lock
npm install
ls
touch newfile.txt
npm run build
ls


ls from inside the run.sh script after build. The public folder is present.



...
Generated public/sw.js, which will precache 6 files, totaling 197705 bytes.
info Done building in 44.842 sec
*ls*
Dockerfile
config
gatsby-config.js
gatsby-node.js
newfile.txt
node_modules
package-lock.json
package.json
postcss.config.js
public
run.sh
src
static
tailwind.css
tailwind.js


ls from inside the Dockerfile. The public folder is missing and trying to interact with it leads to failure.



Removing intermediate container 1692fb171673
---> 474d83267ccb
Step 10/14 : RUN pwd
---> Running in 7c351b151904
/opt/site
Removing intermediate container 7c351b151904
---> bae37da8b513
Step 11/14 : RUN ls
---> Running in 384daf575cae
Dockerfile
config
gatsby-config.js
gatsby-node.js
package-lock.json
package.json
postcss.config.js
run.sh
src
static
tailwind.css
tailwind.js
Removing intermediate container 384daf575cae
---> 1f6743a4adc1
Step 12/14 : RUN ls public
---> Running in 7af84c5d72a0
ls: cannot access public: No such file or directory
The command '/bin/sh -c ls public' returned a non-zero code: 2
ERROR: Job failed: exit code 2









share|improve this question
















After RUN ["./run.sh"], a folder produced by run.sh is visible from inside the script but lost once Docker continues.



Expected behaviour:
I would like to have access to the public/ folder, which is generated by the run.sh script.



Dockerfile



 ...
RUN mkdir -p /opt/site
WORKDIR /opt/site
VOLUME /opt/site
COPY . .

RUN ["chmod", "+x", "./run.sh"]
RUN ["./run.sh"]
RUN pwd
RUN ls
RUN ls public

FROM nginx
COPY --from=build-stage /opt/site/public /usr/share/nginx/html


Script



 #!/usr/bin/env bash
rm -rf public/ node_modules/ node_modules/.bin/ package-lock.json yarn.lock
npm install
ls
touch newfile.txt
npm run build
ls


ls from inside the run.sh script after build. The public folder is present.



...
Generated public/sw.js, which will precache 6 files, totaling 197705 bytes.
info Done building in 44.842 sec
*ls*
Dockerfile
config
gatsby-config.js
gatsby-node.js
newfile.txt
node_modules
package-lock.json
package.json
postcss.config.js
public
run.sh
src
static
tailwind.css
tailwind.js


ls from inside the Dockerfile. The public folder is missing and trying to interact with it leads to failure.



Removing intermediate container 1692fb171673
---> 474d83267ccb
Step 10/14 : RUN pwd
---> Running in 7c351b151904
/opt/site
Removing intermediate container 7c351b151904
---> bae37da8b513
Step 11/14 : RUN ls
---> Running in 384daf575cae
Dockerfile
config
gatsby-config.js
gatsby-node.js
package-lock.json
package.json
postcss.config.js
run.sh
src
static
tailwind.css
tailwind.js
Removing intermediate container 384daf575cae
---> 1f6743a4adc1
Step 12/14 : RUN ls public
---> Running in 7af84c5d72a0
ls: cannot access public: No such file or directory
The command '/bin/sh -c ls public' returned a non-zero code: 2
ERROR: Job failed: exit code 2






shell docker dockerfile






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 10:32







Finn Frotscher

















asked Nov 13 '18 at 10:09









Finn FrotscherFinn Frotscher

142112




142112












  • i have added newfile.txt as a test for precisely this issue

    – Finn Frotscher
    Nov 13 '18 at 10:10











  • do you build it by using docker or docker-compose ?

    – malyy
    Nov 13 '18 at 10:44











  • It is run from a gitlab-ci.yml file. the command is docker build git.finnfrotscher.com/finnfrotscher/finnfrotschercom/blob/…

    – Finn Frotscher
    Nov 13 '18 at 10:50

















  • i have added newfile.txt as a test for precisely this issue

    – Finn Frotscher
    Nov 13 '18 at 10:10











  • do you build it by using docker or docker-compose ?

    – malyy
    Nov 13 '18 at 10:44











  • It is run from a gitlab-ci.yml file. the command is docker build git.finnfrotscher.com/finnfrotscher/finnfrotschercom/blob/…

    – Finn Frotscher
    Nov 13 '18 at 10:50
















i have added newfile.txt as a test for precisely this issue

– Finn Frotscher
Nov 13 '18 at 10:10





i have added newfile.txt as a test for precisely this issue

– Finn Frotscher
Nov 13 '18 at 10:10













do you build it by using docker or docker-compose ?

– malyy
Nov 13 '18 at 10:44





do you build it by using docker or docker-compose ?

– malyy
Nov 13 '18 at 10:44













It is run from a gitlab-ci.yml file. the command is docker build git.finnfrotscher.com/finnfrotscher/finnfrotschercom/blob/…

– Finn Frotscher
Nov 13 '18 at 10:50





It is run from a gitlab-ci.yml file. the command is docker build git.finnfrotscher.com/finnfrotscher/finnfrotschercom/blob/…

– Finn Frotscher
Nov 13 '18 at 10:50












1 Answer
1






active

oldest

votes


















3














You've created a volume with the selected directory:



 VOLUME /opt/site


When defined in an image, a volume will get created for every container created from that image. If you do not specify a source for the volume (which you cannot at build time), docker will create an anonymous volume. And with both a named and anonymous volume, docker will initialize the contents to that of the image at that location.



The result of a RUN command is the following:



  • create a temporary container

  • that temporary container runs your requested command and verifies the exit code before continuing

  • if successful, docker captures the result of a diff between the image and container. This is mainly the container specific read/write filesystem layer. However it does not include any external volumes.

This behaviour is documented by docker:





  • Changing the volume from within the Dockerfile: If any build steps change the data within the volume after it has been declared, those changes will be discarded.



My standard recommendation is to remove any volume definition from the Dockerfile. If you need a volume, define it at runtime with something like a docker compose file. This allows the image to be extended, and prevents anonymous volumes from cluttering the filesystem.






share|improve this answer























  • thank you. just removing the VOLUME /opt/site was enough to make it work.

    – Finn Frotscher
    Nov 13 '18 at 13:09










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278556%2fresult-of-sh-script-run-from-dockerfile-is-not-saved-to-image%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














You've created a volume with the selected directory:



 VOLUME /opt/site


When defined in an image, a volume will get created for every container created from that image. If you do not specify a source for the volume (which you cannot at build time), docker will create an anonymous volume. And with both a named and anonymous volume, docker will initialize the contents to that of the image at that location.



The result of a RUN command is the following:



  • create a temporary container

  • that temporary container runs your requested command and verifies the exit code before continuing

  • if successful, docker captures the result of a diff between the image and container. This is mainly the container specific read/write filesystem layer. However it does not include any external volumes.

This behaviour is documented by docker:





  • Changing the volume from within the Dockerfile: If any build steps change the data within the volume after it has been declared, those changes will be discarded.



My standard recommendation is to remove any volume definition from the Dockerfile. If you need a volume, define it at runtime with something like a docker compose file. This allows the image to be extended, and prevents anonymous volumes from cluttering the filesystem.






share|improve this answer























  • thank you. just removing the VOLUME /opt/site was enough to make it work.

    – Finn Frotscher
    Nov 13 '18 at 13:09















3














You've created a volume with the selected directory:



 VOLUME /opt/site


When defined in an image, a volume will get created for every container created from that image. If you do not specify a source for the volume (which you cannot at build time), docker will create an anonymous volume. And with both a named and anonymous volume, docker will initialize the contents to that of the image at that location.



The result of a RUN command is the following:



  • create a temporary container

  • that temporary container runs your requested command and verifies the exit code before continuing

  • if successful, docker captures the result of a diff between the image and container. This is mainly the container specific read/write filesystem layer. However it does not include any external volumes.

This behaviour is documented by docker:





  • Changing the volume from within the Dockerfile: If any build steps change the data within the volume after it has been declared, those changes will be discarded.



My standard recommendation is to remove any volume definition from the Dockerfile. If you need a volume, define it at runtime with something like a docker compose file. This allows the image to be extended, and prevents anonymous volumes from cluttering the filesystem.






share|improve this answer























  • thank you. just removing the VOLUME /opt/site was enough to make it work.

    – Finn Frotscher
    Nov 13 '18 at 13:09













3












3








3







You've created a volume with the selected directory:



 VOLUME /opt/site


When defined in an image, a volume will get created for every container created from that image. If you do not specify a source for the volume (which you cannot at build time), docker will create an anonymous volume. And with both a named and anonymous volume, docker will initialize the contents to that of the image at that location.



The result of a RUN command is the following:



  • create a temporary container

  • that temporary container runs your requested command and verifies the exit code before continuing

  • if successful, docker captures the result of a diff between the image and container. This is mainly the container specific read/write filesystem layer. However it does not include any external volumes.

This behaviour is documented by docker:





  • Changing the volume from within the Dockerfile: If any build steps change the data within the volume after it has been declared, those changes will be discarded.



My standard recommendation is to remove any volume definition from the Dockerfile. If you need a volume, define it at runtime with something like a docker compose file. This allows the image to be extended, and prevents anonymous volumes from cluttering the filesystem.






share|improve this answer













You've created a volume with the selected directory:



 VOLUME /opt/site


When defined in an image, a volume will get created for every container created from that image. If you do not specify a source for the volume (which you cannot at build time), docker will create an anonymous volume. And with both a named and anonymous volume, docker will initialize the contents to that of the image at that location.



The result of a RUN command is the following:



  • create a temporary container

  • that temporary container runs your requested command and verifies the exit code before continuing

  • if successful, docker captures the result of a diff between the image and container. This is mainly the container specific read/write filesystem layer. However it does not include any external volumes.

This behaviour is documented by docker:





  • Changing the volume from within the Dockerfile: If any build steps change the data within the volume after it has been declared, those changes will be discarded.



My standard recommendation is to remove any volume definition from the Dockerfile. If you need a volume, define it at runtime with something like a docker compose file. This allows the image to be extended, and prevents anonymous volumes from cluttering the filesystem.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 10:55









BMitchBMitch

59.2k9121139




59.2k9121139












  • thank you. just removing the VOLUME /opt/site was enough to make it work.

    – Finn Frotscher
    Nov 13 '18 at 13:09

















  • thank you. just removing the VOLUME /opt/site was enough to make it work.

    – Finn Frotscher
    Nov 13 '18 at 13:09
















thank you. just removing the VOLUME /opt/site was enough to make it work.

– Finn Frotscher
Nov 13 '18 at 13:09





thank you. just removing the VOLUME /opt/site was enough to make it work.

– Finn Frotscher
Nov 13 '18 at 13:09

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53278556%2fresult-of-sh-script-run-from-dockerfile-is-not-saved-to-image%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto