Docker Image and Registry

DockerBeginner
Practice Now

Introduction

In this challenge, we're going to play with Docker images. A Docker container image is a lightweight, self-contained, executable software package that contains everything needed to run an application: code, runtime, system tools, system libraries, and settings.

Change Docker Image

A docker image contains an image name and an image tag, where the image name comprises the repository address and the image identifier. In this subsection, we will push a docker image created by someone else into our repository.

Target

You aim to push the public ubuntu images on dockerhub to your private repository.

Result Example

Here's an example of what you should be able to accomplish by the end of this challenge:

  1. Register yourself on dockerhub and log in.

    Dockerhub registration login screen

  2. Download the ubuntu:22.10 image from the docker hub to our local server.

    Downloading Ubuntu Docker image

  3. Change the ubuntu:22.10 image to our repository address.

    Changing Docker image repository

  4. Sign in to the docker hub.

    Docker Hub login screen

  5. Push the image to the remote repository.

    Pushing image to repository

Requirements

To complete this challenge, you will need:

  • Install the Docker engine.
  • Have some knowledge of the Docker command line.
  • A Docker image already exists that needs to be updated

Build A Web Image

We usually use the nginx to run static applications such as websites. In this section, we will build our web image.

Target

Your goal is to create a Docker container image and package a simple web application into it, then use that image to start the container and make it accessible properly.

Result Example

Here's an example of what you should be able to accomplish by the end of this challenge:

  1. Create a new file called index.html in the /home/labex/Code directory with the content hello labex.

    Creating index html file

  2. Create a new file called Dockerfile with the following contents

    Dockerfile content example

  3. Build your web image with the format of your_dockerhub_id/web:1.1.0.

    Building Docker web image

  4. Push the created web image to the dockerhub.

    Pushing web image to DockerHub

  5. start a container called web with your_dockerhub_id/web:1.1.0, and we also need to map port 80 to the host.

    Starting Docker container web

  6. Use the curl command to visit http://127.0.0.1 and check that the output is hello labex.

    curl command output hello labex

Requirements

To complete this challenge, you will need:

  • Building with Dockerfile
  • Specify the base image as Nginx:latest
  • Expose port 80 in the Dockerfile using the EXPOSE command
  • After the build is complete, make sure the container can run properly and respond to HTTP requests

Multi-stage Image Build

Creating a container image often involves two steps:

  1. Compile the application build.
  2. Create the application image.

This section will combine these two steps into one Docker file to achieve a multi-stage build.

To complete this challenge section, we have prepared a Hello World project at https://github.com/joker-bai/go-hello-world.git.

Target

Your goal is to use a multi-stage build to make a container image and use that image to start a container and have it be accessible properly.

Result Example

Here's an example of what you should be able to accomplish by the end of this challenge:

  1. Create a hello-world directory in the /home/labex/Code directory. Creating hello world directory

  2. Create a Dockerfile in this directory with the following contents Dockerfile creation example

  3. Build the docker image with the format of your_dockerhub_id/go-hello-world:1.1.0. Building Docker image process

  4. Push the image to the docker hub. Pushing Docker image to hub

  5. Start a container called go-hello-world and expose port 8080. Starting go hello world container

  6. Visit http://127.0.0.1:8080 to check if it is OK. Container HTTP response check

Requirements

To complete this challenge, you will need:

  • Building with Dockerfile
  • After the build is complete, make sure the container can run properly and respond to HTTP requests

Summary

Congratulations on the completion of all elements of this challenge, you now have the flexibility to create and manage application images.

✨ Check Solution and Practice✨ Check Solution and Practice✨ Check Solution and Practice