Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Beginning DevOps with Docker

You're reading from   Beginning DevOps with Docker Automate the deployment of your environment with the power of the Docker toolchain

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781789532401
Length 96 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Joseph Muli Joseph Muli
Author Profile Icon Joseph Muli
Joseph Muli
Arrow right icon
View More author details
Toc

Basic Docker Terminal Commands

Open Command Prompt to check that Docker is installed in your workstation. Entering the command docker on your terminal should show the following:

Basic Docker Terminal Commands

This is the list of available subcommands for Docker. To understand what each subcommand does, enter docker-subcommand –help on the terminal:

Basic Docker Terminal Commands

Run docker info and note the following:

  • Containers
  • Images
  • Server Version
Basic Docker Terminal Commands

This command displays system-wide information. The server version number is important at times, especially when new releases introduce something that is not backward-compatible. Docker has stable and edge releases for their Community Edition.

We will now look at a few commonly used commands.

This command searches Docker Hub for images:

docker search <term> (for example, docker search ubuntu)

Docker Hub is the default Docker registry. A Docker registry holds named Docker images. Docker Hub is basically the "GitHub for Docker images". Earlier, we looked at running an Ubuntu container without building one; this is where the Ubuntu image is stored and versioned:

Basic Docker Terminal Commands

"There are private Docker registries, and it is important that you are aware of this now."? Docker Hub is at hub.docker.com. Some images are hosted at store.docker.com but Docker Store contains official images. However, it mainly focuses on the commercial aspect of an app store of sorts for Docker images and provides workflows for use.

The register page is as shown here:

Basic Docker Terminal Commands

The log in page is as shown here:

Basic Docker Terminal Commands

From the results, you can tell how users have rated the image by the number of stars. You can also tell whether the image is official. This means that the image is promoted by the registry, in this case, Docker Hub. New Docker users are advised to use official images since they have great documentation, are secure, promote best practices, and are designed for most use cases. As soon as you have settled on one image, you'll need to have it locally.

Note

Ensure you are able to search for at least one image from Docker Hub. Image variety ranges from operating systems to libraries, such as Ubuntu, Node.js, and Apache.

This command allows you to search from Docker Hub:

docker search <term>

For example, docker search ubuntu.

This command pulls an image from the registry to your local machine:

docker pull

For example, docker pull ubuntu.

As soon as this command is running, you'll notice that it is using the default tag: latest. In Docker Hub, you can see the list of tags. For Ubuntu, they are listed here: https://hub.docker.com/r/library/ubuntu/ plus their respective Dockerfiles:

Basic Docker Terminal Commands

Download the Ubuntu image profile on Docker Hub from: https://hub.docker.com/r/library/ubuntu/.

Activity 1 — Utilizing the docker pull Command

To get you conversant with the docker pull command.

The goal of this activity is to gain a firm understanding of the docker-pull CLI, not only by running the listed commands, but also by seeking help on other commands while exploring, through manipulating the built containers.

  1. Is Docker up and running? Type docker on the terminal or command-line application.
  2. This command is used to pull the image from the Docker Hub.
    docker pull
    

Image variety ranges from operating systems to libraries, such as Ubuntu, Node.js, and Apache. This command allows you to pull images from Docker Hub:

For example, docker pull ubuntu.

This command lists the Docker images we have locally:

  • docker images

When we run the command, if we have pulled images from Docker Hub, we will be able to see a list of images:

Activity 1 — Utilizing the docker pull Command

They are listed according to the repository, tag, image ID, date created, and size. The repository is simply the image name unless it is sourced from a different registry. In this case, you'll have a URL without the http:// and the top level domain (TLD) such as >registry.heroku.com/<image-name> from the Heroku registry.

This command will check whether the image by the name hello-world exists locally:

docker run <image>

For example, docker run hello-world:

Activity 1 — Utilizing the docker pull Command

If the image is not local, it will be pulled from the default registry, Docker Hub, and run as a container, by default.

This command lists the running containers:

docker ps

If there aren't any running containers, you should have a blank screen with the headers:

Activity 1 — Utilizing the docker pull Command

Activity 2 — Analyzing the Docker CLI

Ensure you have the Docker CLI running by typing docker on your terminal.

You have been asked to demonstrate the commands covered so far.

To get you conversant with the Docker CLI. The goal of this activity is to gain a firm understanding of the docker-compose CLI, not only by running the listed commands, but also by seeking help on other commands while exploring, through manipulating the built containers. The goal is to be flexible enough with the CLI to be able to use it in a real-world scenario such as running an automated script.

  1. Is Docker up and running? Type docker on the terminal or command-line application.
  2. Search for the official Apache image using the CLI, using docker search apache:
    Activity 2 — Analyzing the Docker CLI
  3. Attempt to pull the image using docker pull apache.
  4. Confirm the availability of the image locally using docker images.
  5. Bonus: Run the image as a container using docker run apache.
  6. Bonus: Stop the container using docker stop <container ID>.
  7. Bonus: Delete the container and the image using docker rm <container ID>.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image