I have a docker-compose stack running on a remote server with 5 services. On the server, the file structure looks like this:
.
├── devcontainers
│ ├── AssetCompiler
│ │ └── .devcontainer
│ │ ├── devcontainer.json
│ │ └── setup.sh
│ ├── DocumentStore
│ │ └── .devcontainer
│ │ ├── devcontainer.json
│ │ └── setup.sh
│ └── docker-compose.devcontainer.yml
├── docker-compose.override.yml
└── docker-compose.yml
To develop the application remotely, I connect to the remote sever in VS Code (using Remote-SSH), enter one of the devcontainer root folders (for instance devcontainers/DocumentStore
) and execute Dev Containers: Reopen in Container
from the VS Code Command Palette.
Both devcontainers use the same docker image which is based on the Microsoft dotnet devcontainer image.
#
# Use the devcontainer SDK as a basis
#
FROM mcr.microsoft.com/devcontainers/dotnet
# - Install additional packages
RUN apt-get update &&
apt-get install --no-install-recommends -y
dumb-init
npm
ssh &&
apt-get clean
WORKDIR /app
# - Expose the webserver port that we will be using to access the application
EXPOSE 4812 4813
# - Opt out of the MS telemetry function
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
# - Use the polling file watcher
ENV DOTNET_USE_POLLING_FILE_WATCHER=true
ENTRYPOINT ["sleep", "infinity"]
The devcontainer.json looks like this:
{
"name": "DocumentStore",
"dockerComposeFile": [
"../../../docker-compose.yml",
"../../../docker-compose.override.yml",
"../../docker-compose.devcontainer.yml"
],
"service": "documentstore",
"overrideCommand": false,
"workspaceFolder": "/workspace",
"customizations": {
"vscode": {
"settings": {},
"extensions": [
"ms-dotnettools.csharp",
"ms-dotnettools.csdevkit",
"augustocdias.tasks-shell-input"
]
}
},
"shutdownAction": "none",
"postCreateCommand": ["/.devcontainer/setup.sh"],
"remoteUser": "1000"
}
The setup.sh script clones the source code if it does not exist and should only run when the container is spinning up for the first time. Like this:
#!/bin/bash
rootpathos="/workspace"
if [ ! -d "$rootpathos/.git" ]; then
cd "$rootpathos"
echo "=> Cloning the repository <="
cd "$rootpathos"
git clone --recurse-submodules ssh://<<path to repro>> .
git submodule update --init --recursive
git submodule update --recursive
echo "=> Done cloning repository <="
echo "=> Setting up additional components <="
npm install
echo "=> Done setting up additional components <="
else
echo "=> All has been setup already <="
fi
In the different docker-compose.yml files, I do not overwrite the entrypoint of the container.
When my devcontainer launches, I need to start the dotnet app like this dotnet watch run --project DocumentStore
Can you help me with the following:
(1) Terminal process stops when I exit the devcontainer using “Close Remote Connection”
How can I leave my dotnet process running in the container when I close the remote connection? With the current setup, the dotnet process seems to stop immediately when I close the connection.
(2) Setup.sh script asks me to hit a key with this message “Done. Press any key to close the terminal.”
It’s great that I can see the progress of the setup script, but is there any way that the startup process can continue without having to hit a key?
(3) Is there any way to start the dotnet process (command dotnet watch run --project DocumentStore
) when the container launches for the first time (after completion of setup.sh)?
Your input would be greatly appreciated!