VK Cloud logo
Updated at April 15, 2024   08:50 AM

Using Docker CE

Docker CE allows working with Docker images and managing containers. To do this, the Docker CLI commands are used. The Docker command comprises options and subcommands:

docker [OPTIONS] SUBCOMMAND

To view the Docker CLI help, run the commands:

docker --help
docker SUBCOMMAND --help

See the official documentation for more details about working with Docker.

Before you begin

Make sure that:

  • You have an access to the terminal of the host, on which Docker CE is installed.
  • You can use sudo on that host to run the commands on behalf of superuser (root).

Working with images

Containers are created from the Docker images. By default, Docker pulls images from the Docker Hub (it is a Docker registry).

The Ubuntu OS image will be used as example to demonstrate how to work with images:

  1. View available Ubuntu images in Docker Hub:

    sudo docker search ubuntu

    The command's output will contain the list of images, which satisfy the search criteria.

  2. Pull the ubuntu image:

    sudo docker pull ubuntu

    The command's output will contain the information about the pulling progress.

  3. Make sure that the image was pulled by viewing the pulled images:

    sudo docker images

    The command's output will contain the list of pulled images.

Creating and running container

To create and run a container, which uses the pulled image, employ the docker run command. This command is a combination of the docker create and the docker start commands.

The operation will be demonstrated for the previously pulled ubuntu image:

  1. Create and run the container:

    sudo docker run -it ubuntu

    After running the container, you will get access to the container's terminal (TTY) with the bash session (this is achieved with -it options). As a result, you will get the bash command line prompt, which looks like:

    root@8502eb90112b:/#

    In this example output, 8502eb90112b is an identifier of the created container.

  2. To check that the container is operational, install Node.js into it.

    1. Run the command:

      apt update && apt install nodejs -y
    2. View the information about installed Node.js version:

      node -v

      Example output:

      v12.22.9
  3. Exit the container's bash command line:

    exit

    The container will be stopped.

Managing containers

  1. To manage containers it is necessary to obtain their identifiers. To do this, view the list of the containers:

    sudo docker ps -a

    A container identifier is listed in the CONTAINER ID column.

  2. Manage a container, using its identifier:

    sudo docker start <container identifier>

    Example command to start the ubuntu container with the 8502eb90112b identifier:

    sudo docker start 8502eb90112b