title | description | ms.topic | ms.date |
---|---|---|---|
Create a container image for a Node.js app from Visual Studio Code |
Tutorial part 4, create a Node.js application image |
conceptual |
09/20/2019 |
Previous step: Create and run a local Node.js app
-
In Visual Studio Code, open the Command Palette (F1), type
add docker files to workspace
, then select the Docker: Add Docker files to workspace command. -
When prompted, select Node.js for the application type, answer No for Docker compose files, then select the port on which your application listens (should be 3000).
-
The command creates a
Dockerfile
along with some configuration files for Docker compose and a.dockerignore
.[!TIP] VS Code has great support for Docker files. See the Working with Docker in the VS Code documentation to learn about rich language features like smart suggestions, completions, and error detection.
The Dockerfile
describes the environment for your app including the location of the source files and the command to start the app within a container.
Tip
Containers versus images: A container is an instance of an image.
-
Open the Command Palette (F1) and run Docker Images: Build Image to build the image. VS Code uses the Dockerfile in the current folder and gives the image the same name as the current folder.
-
Once completed, the Terminal panel of Visual Studio Code opens to run the
docker build
command. The output also shows each step, or layer, that makes up the app environment. -
Once built, the image appears in the DOCKER explorer under Images.
-
To push the image to a registry, you must first tag it with the registry name. In the DOCKER explorer, right-click the latest image.
-
In the prompt that follows, complete the tags and press Enter.
By convention, tagging uses the following format:
[registry or username]/[image name]:[tag]
If you're using the Azure Container Registry, your image name would be similar to the following:
msdocsvscodereg.azurecr.io/myexpressapp:latest
If you are using Docker Hub, use your Docker Hub username. For example:
fiveisprime/myexpressapp:latest
-
The newly-tagged image appears now in a node under Images that includes the registry name. Expand that node, right-click latest, and select Push.
-
The Terminal panel shows the
docker push
commands used for this operation. The target registry is determined by the registry specified in the image name.[!IMPORTANT] If the output displays "Authentication required", run
az acr login --name <your registry name>
in the terminal. -
Once completed, expand the Registries node in the Docker extension explorer to see your image in the registry.
[!div class="nextstepaction"] I've created an image for my application I ran into an issue