How to install and use Docker on Raspberry Pi

Docker is a container platform, allows you to quickly build, test and deploy applications, as a portable, self-contained container, you can run almost anywhere.

In this tutorial, we will explain how to install Docker on the Raspberry Pi Docker and explore the basic concepts and commands.

prerequisites

We assume that you installed on Raspbian Pi Raspberry . Docker not need a graphical interface, it is preferable to use Raspbian Stretch Lite image and enable S SH. Thus, Raspberry Pi will have more available processing power and memory to run Docker containers.

Docker installed on Raspberry Pi

Installation Docker only need to run some commands on the Raspberry Pi.

First, use the following curl command to download Docker installation script:

curl -fsSL https://get.docker.com -o get-docker.sh

After the download is complete, type the following command to execute the script:

sh get-docker.sh

The script will detect the Linux distribution, install the required package and start Docker.

This process may take several minutes, after the completion of the script will output about Docker Docker version and how the information is used as a non-root user.

Upon completion, Docker on the installation of Pi board.

Docker execute commands without Sudo case

By default, only users with administrative privileges can execute Docker command.

To run the command without prior Docker add sudo, you need to add users to the docker groups created during the installation of a non-root user. Do this by type:

sudo usermod -aG docker $USER

Save $ USER environment variable is a user name.

Log off and log back on to refresh the group membership.

To verify that you can not use the sudo command to run and run docker download the test image commands directly, run it, print "Hello from Docker" message and exits in the container:

docker container run hello-world

The output looks like this:

How to use the Docker

Now Docker already installed on your Raspberry Pi and set up, let's look at the basic concepts and commands docker.

Docker Mirror

Docker mirror file system consists of a series of layers, which represents the file system layer constituting Dockerfile application executable software instructions in the mirror. Immutable image is a binary file, including all other dependencies needed to run the application and the application, such as the library, and binary instructions.

Docker Docker provides most of the mirror on the Hub. It is a cloud-based registration services, which includes other features for Docker image stored in a public or private repository.

From Docker Hub search the registry mirroring, please use the docker search command. For example, to search for Debian mirror, you can type:

docker search debian

Docker container

Examples of containers called mirroring. Container stands for running a single application, process or service time.

It may not be the most appropriate analogy, but if you are a programmer, you can like Docker seen as mirroring the Docker container as an instance of the class.

To start, stop, delete, and manage containers, use this command docker container. For example, the following command starts Docker containers on Debian mirrors. If you do not have a local mirror, the first download it:

docker container run debian

Debian container will stop immediately after the start, because it does not have a long-running process, nor does it provide other commands. Container starts, run a null command, and then exit.

This option -it allows you to interact with the container via the command line. To start an interactive container type:

docker container run -it debian /bin/bash
root@ee86c8c81b3b:/#

As you can see from the above output when the container starts as a command prompt has changed, which means that you are now working from the inside of the container:

To list events Docker container, use the following command:

docker container ls

If you do not have any container are running, the output will be empty.

To view the active and inactive of all containers, use the -a option:

docker container ls -a

To delete one or more containers, container ID just copy and paste them in the container rm command:

docker container rm c55680af670c

in conclusion

You have learned how to install Docker on the Raspberry Pi machines and how to run Docker containers. For more information about this topic, please see the Docker official documents .

Guess you like

Origin www.linuxidc.com/Linux/2019-08/159961.htm