Running and inspecting images

You can run any image in a container from within VS Code. VS Code also provides functionality for inspecting, managing and otherwise working with images and containers on your machine.

Exercise
Answer
Exercise
  • Run the "i-love-lamp:latest" image from the Docker Explorer in VS Code

  • View the application running on port 3000

  • View the image logs

  • Attach a shell to the running image and inspect the file system

  • Stop the image

  • Remove the image

Answer
  • Open the Docker Explorer view by clicking on the Docker icon in the Activity Bar

  • In the "images" section, locate the "i-love-lamp" image. Expand it to find the "latest" image.

  • Right-click the image and select "Run"

  • Notice that there is now a container running

  • Open your browser and navigate to "http://localhost:3000"

  • View the application running in the Docker container

  • Right click the container in the "Containers" section of the Docker Explorer view and select "View Logs"

  • View the logs from the container

  • Right click the container in the "Containers" section of the Docker Explorer view and select "Attach Shell"

  • The integrated terminal will open connected to the Docker container

  • Navigate the file system with cd to change directory and ls to list the file system contents

Note that if you navigate to "/" with cd /, you will get to the root of the container. Notice how it appears as if the container is an entire Linux machine with a complete file system.

  • Right click the container in the "Containers" section of the Docker Explorer view and select "Stop"

  • Right click the container in the "Containers" section of the Docker Explorer view and select "Remove"

  • The container will be removed from the "Containers" section in VS Code