Introduction to Docker: A Beginner's Tutorial with the Docker Whale Say Container

Docker is a powerful platform for developing, shipping, and running applications in isolated environments called containers. This tutorial will guide you through the basics of Docker, from installation to running your first container using the Docker Whale Say image. For more information about Docker, visit their website here.

For a list of useful Docker commands, visit NeuroNest's Docker Command Cheet Sheet

Prerequisites

  • A computer with a modern operating system (Windows, macOS, or Linux).
  • Basic understanding of the command line.

1. Install Docker

Windows:

  1. Download Docker Desktop for Windows.
  2. Follow the installation instructions.
  3. Ensure you have the Windows Subsystem for Linux (WSL) 2 installed and set up.

mac OS:

  1. Download Docker Desktop for Mac.
  2. Follow the installation instructions.

Linux:

Follow the instructions on the official Docker documentation.

After installation, you can verify Docker is installed correctly by opening a terminal window and running:

docker --version

2. Running Your First Docker Container

  1. Open your terminal.
  2. Run the following command to pull the Docker Whale Say image from Docker Hub:
  3. docker pull docker/whalesay

    This command downloads the Docker Whale Say image from Docker Hub to your local machine.

  4. Once the image is downloaded, you can create and run a container using this image:
  5. docker run docker/whalesay cowsay "Hello, Docker!"

    This command starts a new container from the Docker Whale Say image and displays a fun message.

     ___________________
    < Hello, Docker! >
     -------------------
        \
         \
          \
                        ##        .
                  ## ## ##       ==
               ## ## ## ##      ===
           /""""""""""""""""___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
           \______ o          __/
            \    \        __/
             \____\______/
            

3. Understanding Docker Basics

  • Images: Read-only templates that contain a set of instructions for creating a container. For example, the Docker Whale Say image contains a simple application that displays a fun message.
  • Containers: Runnable instances of images. Containers are lightweight and can be started, stopped, and moved around easily.
  • Dockerfile: A text file that contains instructions for building a Docker image. (Not used in this simple example, but essential for more complex applications.)

4. Managing Docker Containers and Images

List running containers:

docker ps

Since the Docker Whale Say container exits after displaying the message, it won't show up in the list of running containers.

List all containers (including stopped ones):

docker ps -a

Remove a stopped container:

docker rm <container_id>

Replace <container_id> with the ID of the container you want to remove, which you can find from the docker ps -a command.

List all images:

docker images

Remove an image:

docker rmi docker/whalesay

5. Conclusion

This tutorial covered the basics of Docker, including installation, running a simple Docker Whale Say container, and basic container management commands. Docker is a versatile tool that can greatly streamline the development and deployment process. With these basics, you can start exploring more advanced features and use cases for Docker.

Happy Dockering!

6. Reference and Additional Resources