Search code examples
dockerfilesystemsdocker-volume

Running a container with a Docker bind-mount causes container to return Node version and exit


I am trying to attach a directory of static assets to my docker instance after it has been built. When I do something like this

docker run -it app /bin/bash

The container runs perfectly fine. However, if I do something like this:

docker run -it app -v "${PWD}/assets:/path/to/empty/directory" /bin/bash

This also reproduces it:

docker run -it node:12.18-alpine3.12 -v "${PWD}/assets:/path/to/empty/directory" /bin/bash

It spits out the version of Node v12.18.4 I am using and immediately dies. Where am I going wrong? I am using docker with wsl2 on windows 10. Is it due to filesystem incompatibility?

edit: whoops it's spitting out the node version and not the alpine version


Solution

  • To debug my issue I tried running a bare-bones alpine container:

    docker run -it alpine:3.12 -v "${PWD}/assets:/usr/app"  /bin/sh
    

    Which gave a slightly more useful error message:

    docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"-v\": executable file not found in $PATH": unknown.

    From this I realized that docker was trying to run -v as a starting command. I decided to change the order around, things started working.

    TL;DR The -v argument and its corresponding parameter must be placed before the container name when performing a docker run command. i.e. the following works

    docker run -it -v "${PWD}/assets:/usr/app" alpine:3.12 /bin/sh
    

    but this doesn't:

    docker run -it alpine:3.12 -v "${PWD}/assets:/usr/app"  /bin/sh