Why
-
By looking at the
Dockerfile
clearly we wouldn't want to install those dependencies at the developer's machine because some may use windows, some may use mac. -
By using dev container, we can unify the dev environment.
Project Structure
devcontainer.json
{ "name": "For Kafka", "build": { "dockerfile": "Dockerfile" } }
Dockerfile
FROM node:20-alpine RUN apk --no-cache add \ bash \ g++ \ ca-certificates \ lz4-dev \ musl-dev \ cyrus-sasl-dev \ openssl-dev \ make \ python3 RUN apk add --no-cache --virtual .build-deps gcc zlib-dev libc-dev bsd-compat-headers py-setuptools bash
-
Note that we don't write
RUN npm install <package-name>
inside theDockerfile
because by default we are at the root level inside the container where we are not allowed toWRITE
at that level. -
Even we
mkdir -p
andWORKDIR
at a directory and successfullynpm install
, but inside container we are at the workspace defined by the vscode extentionRemote Development
rather than the directory specified byWORKDIR
. -
The correct procedure should be to install just the native linux libraries, and then we install runtime-specific library inside the container.
-
Note that the
node_modules
installed inside the container will be linux-specific, running it in windows will fail.
Open the Project Inside dev Container
-
Click the lower-left button in vs-code:
-
Choose
Reopen in Container
-
Choose the configuration we have just named: