Solution to Challenge

Learn the solution to the challenge you completed.

We'll cover the following

Solution

  1. To build and tag an image in a single command with challenge and try as image and tag name respectively:

    docker image build -t <your_username>/challenge:try .
    

    or for Dockerfile.prod:

    docker image build -f Dockerfile.prod -t <your_username>/challenge:try .
    
  2. List down all images:

    docker image ls
    
  3. Push your image to the repository:

    docker push <your_username>/challenge
    

    or with tag:

    docker push <your_username>/challenge:try
    
  4. Verify on your repository that the image has been built.

  5. A container is run according to the required instructions, using the image you built above:

    docker run -it --rm --name nodecontainer -p 8080:3000 \
    <your_username>/challenge:try
    
    • -it runs an interactive session.
    • --rm removes the container after the container stops.
    • --name is used to name the container as nodecontainer.
    • -p is used to define both the exposed port (8080) and the default port (3000) on which node is running.
    • Image name is <your_username>/challenge:try that was built above.
  6. Click on the URL in front of β€œYour app can be found here:” to verify if your app is up successfully.

πŸ“Œ Click on the β€œRun” button to view the solution running.

πŸ“Œ The tag has been changed to solved, so your correct image does not get overwritten.

Get hands-on with 1400+ tech skills courses.