Skip to content

Instantly share code, notes, and snippets.

@normoes
Last active March 12, 2019 13:33
Show Gist options
  • Save normoes/848bc9f27e837520c50533f12b18bd73 to your computer and use it in GitHub Desktop.
Save normoes/848bc9f27e837520c50533f12b18bd73 to your computer and use it in GitHub Desktop.
docker troubleshooting

Text file is busy

When executing a file whose permissions were changed earlier, a Text file is busy error could appear.

RUN cd scripts/test_env \
    && chmod +x test.prepareapp.sh
    && ./test.prepareapp.sh

It helps to add sync after changing permissions on the file:

RUN cd scripts/test_env \
    && chmod +x test.prepareapp.sh \
    && sync \
    && ./test.prepareapp.sh

chown and docker image size

This way, two docker image layers are created.

COPY . /code
RUN chown -R user_name:user_name /code

In the above case, the parent folder code and everything inside will be owned by user_name.

The line that executes chown adds the same amount of data to the second layer - creating a bigger docker image.

This can be resolved by doing the following (only one docker image layer):

COPY --chown=user_name:user_name . /code

The above case has one problem - The parent folder code is still owned by root.

This can be resolved by changing the ownership of only the parent folder code afterwards (no -R) (two docker image layers again, see table below for comparison).

COPY --chown=user_name:user_name . /code
RUN chown user_name:user_name /code

The following example assumes a directory size of 440MB.

in Dockerfile docker image size [MB]
COPY . /code 414MB
COPY . /code
RUN chown -R user_name:user_name /code
823MB
COPY --chown=user_name:user_name. /code 414MB
COPY --chown=user_name:user_name . /code
RUN chown user_name:user_name /code
414MB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment