What really happens when I set `overrideCommand` on .devcontainer.json?

28 views Asked by At

First of all, sorry for my english and if my question sounds dumb. I tried to search for something like that, read a lot, but I can't seem to find anything related.

I'm using the DevContainers extension on VSCode where I'm setting up a container for my team so my team can develop.

This is what it looks like:

{
  "name": "ContainerName",
  "overrideCommand": false,
  "workspaceFolder": "/app",
  "workspaceMount": "type=volume,source=app-volume,target=/app",
  "build": {
    "context": "..",
    "dockerfile": "Dockerfile"
  },
  "runArgs": [
    "--name",
    "container-name"
  ],
}

The Dockerfile looks like that:

FROM node:lts-slim

EXPOSE 3000

WORKDIR /app

COPY . .

RUN apt-get -y update && apt-get -y install git

RUN echo "PS1=\"\${debian_chroot:+(\$debian_chroot)}\e[1m\e[34m\${HOST_USER:user}\e[32m@\e[34mcontainer-name\e[00m:\e[90m\w\e[00m\\$ \"" >> ~/.bashrc

ENTRYPOINT [ "/bin/bash" ]

This is the COMMAND that I get when I run docker ps -a --no-trunc (formatted for better visualization):

/bin/sh -c '
    echo Container started
    trap "exit 0" 15
    
    exec "$@"
    while sleep 1 & wait $!; do
        :
    done
' - /bin/bash

I know that, when I'm using the overrideCommand with the false value I should pass a command like sleep infinity so the container remains running, as we can see here.

But why? If I just erase the key overrideCommand and in my Dockerfile I remove my ENTRYPOINT layer (or even let it there, it'll be ignored), I get the exact same command as if my overrideCommand were false.

But when the overrideCommand is false, it seems my container closes before even executing the while code.

Error response from daemon: container 3199c093... is not running
Start: Run in container:  (command -v getent >/dev/null 2>&1 && getent passwd 'root' || grep -E '^root|^[^:]*:[^:]*:root:' /etc/passwd || true)
Stdin closed!
Error: An error occurred setting up the container.

And again, why? I don't know if I'm missing something, but to me the commands of the containers generated when overrideCommand is true and when it's false are exactly the same but the false one it's closing all the time when the container starts.

I tried with many ~workarounds~, but I can't seem to find any reason for why this is happening.

When I have a CMD [ "sleep", "infinity" ] it works well, but I just can't understand why I need to have this layer when the override command is exactly the same.

My goal is to have a script running but without using the postStartCommand because I want something really customized to the project. (I know, but well it lead me to a curiosity).

I'd be really glad to have a light on that, and again I'm sorry if all of this sounds dumb. Docker and DevContainers put me in this magnificent world of Linux and scripts and I'm really enjoying learning and discover the new things.

0

There are 0 answers