Linux Commands and Scripts

How to Use Docker?

In this article, we will learn how to use Docker.

Refer this article, if you want to learn how to install Docker on Fedora 29.

Docker is a set of platform as a service products that uses OS-level virtualization to deliver software in packages called containers. Docker simplifies and accelerates your workflow, while giving developers the freedom to innovate with their choice of tools, application stacks, and deployment environments for each project.

1. Search Docker Images

First of all search Docker container images from Docker hub. For example, below command will search all images with Fedora and list as output

# docker search fedora

2. Download Docker Images

Now download the Docker container with name Ubuntu on your local system using following commands.

# docker pull fedora

Using default tag: latest
latest: Pulling from library/fedora
0be2a68855d7: Extracting [==============================>     ]  69.63MB/89.87MB

Now make sure that the above images have been downloaded successfully on your system. Below command list all images.

# docker images

REPOSITORY  TAG            IMAGE ID            CREATED             VIRTUAL SIZE ubuntu      latest         36248ae4a9ac        2 days ago          188 MB fedora      latest         26ffec5b4a8a        2 weeks ago         275MB

3. Launch New Container with Image

Finally, launch a Docker container using the above-downloaded image on your system. Below command will start a new container.

# docker run -i -t -d fedora /bin/bash

To view all running containers type

# docker ps

CONTAINER ID     IMAGE     COMMAND        CREATED          STATUS         PORTS    NAMES
695efa2ace69     fedora    “/bin/bash”    58 seconds ago   Up 56 seconds           first_fedora

By default Above command will list only running containers. To list all containers (including stopped container) use the following command.

# docker ps -a

4. Start/Stop/Attach Container

You can start, stop or attach to any containers with following commands. To start container use following command.

# docker start CONTAINER_ID

To stop container use following command.

# docker stop CONTAINER_ID

To attach to currently running container use following command.

# docker attach CONTAINER_ID We’ll help you.]

That’s it. We have seen how to use Docker. Some basic commands.

[Need assistance to fix this error or install tools? We’ll help you.]

Related Articles