Customize Docker Whale's Language

DockerBeginner
Practice Now

Introduction

Ahoy, Docker linguist! You've mastered making the Docker whale speak, but can you make it multilingual? In this challenge, you'll create a Docker image that uses environment variables to change the language of the whale's greeting. Get ready to give our cetacean friend a global voice!

Create a Polyglot Whale

Imagine you're developing a multilingual application, and you need a way to quickly test your Docker setup in different language environments. That's where our polyglot whale comes in!

In this challenge, you'll take your Docker skills to the next level by creating a flexible, language-aware container. You'll use environment variables - a powerful tool in the Docker ecosystem - to dynamically change the language of our friendly Docker whale's greeting.

Before we dive in, let's set up your challenge environment. Navigate to the ~/project/docker directory in your terminal. You'll find some starter files there, courtesy of your Docker mentor. These files will give you a head start, allowing you to focus on the core concepts of this challenge.

Ready to give our cetacean friend a global voice? Let's make waves in the world of multilingual containers!

Tasks

Your linguistic mission, should you choose to accept it, is to:

  1. Examine the provided entrypoint.sh script to understand how it handles different languages.
  2. Modify the Dockerfile to incorporate the entrypoint.sh script and set up environment variables.
  3. Build a Docker image from your completed Dockerfile.
  4. Run containers from your image, experimenting with different language settings.

Requirements

To successfully complete this challenge, you must:

  1. Use the docker/whalesay as the base image in your Dockerfile.
  2. Create an environment variable named WHALE_LANGUAGE in your Dockerfile, with a default value of "English".
  3. Use the COPY instruction in your Dockerfile to copy the provided entrypoint.sh script into the root directory (/) of your image, naming it /entrypoint.sh. Ensure it has execute permissions and set it as the ENTRYPOINT.
  4. Build your image with the tag polyglot-whale.
  5. Run your container with the environment variable set to make the whale speak both English and Spanish.
  6. Execute all commands in the ~/project/docker directory.

Remember, the entrypoint.sh script is already provided for you. Your main task is to create a Dockerfile that correctly utilizes this script and allows for language customization via environment variables.

Example

When you run your container with Spanish selected, you should see output similar to this:

docker run -e WHALE_LANGUAGE=Spanish polyglot-whale
 _________
< ¡Hola! >
 ---------
    \
     \
      \
                    ###        .
              ### ### ###       ==
           ### ### ### ###      ===
       /""""""""""""""""___/ ===
  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
       \______ o          __/
        \    \        __/
          \____\______/

And when run with the default English setting:

docker run polyglot-whale
 _________
< Hello! >
 ---------
    \
     \
      \
                    ###        .
              ### ### ###       ==
           ### ### ### ###      ===
       /""""""""""""""""___/ ===
  ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
       \______ o          __/
        \    \        __/
          \____\______/

Summary

In this challenge, you've expanded your Docker skills by creating an image that uses environment variables for configuration. You've learned how to:

  1. Use environment variables in a Dockerfile to set default values.
  2. Create a simple shell script to act as an entrypoint for your container.
  3. Override environment variables when running a container.

These skills are crucial for creating flexible, configurable Docker images that can adapt to different environments or use cases. As you continue your Docker journey, remember that environment variables are a powerful tool for making your containers more versatile and easier to manage across different deployment scenarios. Keep exploring and happy whale-speaking!

✨ Check Solution and Practice