Difficulty: Beginner
Estimated Time: 10 minutes

In this first scenario, we'll explore how you can start and connect to your first container using Docker. The environment has been configured with the latest version of the Docker Engine and client which can be accessed via the command line.

The machine name Docker is running on is called docker. If you want to access any of the services, then use docker instead of localhost or 0.0.0.0.

What Is Docker?

Docker describes themselves as "an open platform for developers and sysadmins to build, ship, and run distributed applications".

Docker allows you to run containers. A container is a sandboxed process running an application and its dependencies on the host operating system. The application inside the container considers itself to be the only process running on the machine while the machine can run multiple containers independently. As they're sandboxed, you avoid the possibility of conflicts between dependencies and simplify deployment as all installation and configuration are done ahead of time.

Docker has three key components. First is the Docker Engine, which provides a way to start containers on multiple different operating system platforms. Second is the Docker client, which allows you to communicate with the Engine. Third is the public Docker Registry that hosts Docker Images. These images can be launched or extended to match your requirements and application deployment.

Here we've demonstrated how to start containers in the foreground and background, bind ports and map directories. These commands are the cornerstone of running Docker in both development and production environments.

We'll be using these commands as we learn more about what Docker has to offer in the coming scenarios.

In the next scenario, we'll look into how you can build your own Docker image.

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Launching Containers

Step 1 of 6

Step 1 - Running A Container

With Docker, all containers are started based on a Docker Image. These images contain everything required to launch the process; the host doesn't require any configuration or dependencies.

To start a container, you can either build your Docker image or, as in this scenario, use an existing image created by Docker and the community. Existing images can be found at registry.hub.docker.com/ or by using the command docker search <image-name>. For example, to find an image for Redis, an object-relational database system, you would use docker search --filter=stars=3 redis.

The --filter=stars=3 option indicates that only images with at least three stars should be displayed. People give projects they recommend a star rating on the Docker Registry. It's recommended you either go with the "Official" docker image which has been verified by Docker, or the one with the most stars.

Task

To complete this step, launch a container in the background running an instance of Redis based on the official image.

After identifying the image name using search, you can launch it using docker run <options> <image-name>. By default, Docker will run a command in the foreground. To run in the background, you need to specify the option -d.

At this stage, you will not have a local copy of the image so that it will be downloaded from the Docker registry. If you launch a second container, the local image will be used.

Protip

All containers are given a name and id for use in other Docker commands. You can set the friendly name by providing the option --name <new-name> when launching a container such as --name redis