Skip to main content

Docker Usage

This section demonstrates how to use Docker through common commands. All commands are executed in the terminal of the Radxa Cubie A7A.

tip

Image: An image is a read-only template that contains the application and its runtime environment (including dependencies, libraries, configuration files, etc.).

Container: A container is a running instance of an image, providing an executable environment based on the image. It includes the application and all dependencies but is isolated from the host system.

View Help

You can use Docker's built-in help command to view the usage of all Docker commands.

radxa@device$
docker --help

The terminal will output information similar to the following:

Usage: docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
--config string Location of client config files (default "/home/radxa/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context
set with "docker context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/home/radxa/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/home/radxa/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/home/radxa/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit

Management Commands:
builder Manage builds
completion Generate the autocompletion script for the specified shell
config Manage Docker configs
container Manage containers
context Manage contexts
image Manage images
manifest Manage Docker image manifests and manifest lists
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes

Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.

To get more help with Docker, check out our guides at https://docs.docker.com/go/guides/

View Docker System Information

Use the docker info command to view Docker system information, including Docker version, system configuration, storage driver, network configuration, etc.

radxa@device$
docker info

The terminal will output information similar to the following:

Client:
Context: default
Debug Mode: false

Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 1
Server Version: 20.10.24+dfsg1
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 1.6.20~ds1-1+deb12u1
runc version: 1.1.5+ds1-1+deb12u1
init version:
Security Options:
seccomp
Profile: default
cgroupns
Kernel Version: 6.1.84-7-rk2410-nocsf
Operating System: Debian GNU/Linux 12 (bookworm)
OSType: linux
Architecture: aarch64
CPUs: 8
Total Memory: 3.829GiB
Name: rock-4d-spi
ID: NOPY:K5AM:5IDH:CS7I:VUGO:2U4I:YCZZ:MHNC:SV3D:4GEE:X55W:YQZU
Docker Root Dir: /var/lib/docker
Debug Mode: false
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

View Version Information

To view only the Docker version information, use the docker --version command.

radxa@device$
docker --version

The terminal will output information similar to the following:

Docker version 20.10.24+dfsg1, build 297e128

Pull an Image

Use the docker pull command to pull an image from the cloud (Docker Hub by default).

radxa@device$
docker pull <image_name>

# Example: Pull the latest hello-world image

docker pull hello-world

After successfully pulling the image, the terminal will output information similar to the following:

Using default tag: latest
latest: Pulling from library/hello-world
c9c5fd25a1bd: Pull complete
Digest: sha256:0b6a027b5cf322f09f6706c754e086a232ec1ddba835c8a15c6cb74ef0d43c29
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest

Run a Container

If the image is not available locally, Docker will automatically pull the image from the cloud and then run the container.

radxa@device$
docker run <image_name>

# Example: Run the latest hello-world image

docker run hello-world

After successfully running the container, the terminal will output information similar to the following:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(arm64v8)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

Run a Container in Interactive Mode

In interactive mode, the container remains running, and you can directly operate the container in the terminal until you type exit to exit the container.

radxa@device$
docker run -it <image_name> /bin/bash

# Example: Run the ubuntu:24.04 image in interactive mode

docker run -it ubuntu:24.04 /bin/bash

After successfully running the container, the terminal will output information similar to the following, where 8a18a7ee0838 is the container ID:

root@8a18a7ee0838:/#

Type exit inside the container to exit.

Access the Same Container from Multiple Terminals

radxa@device$
docker exec -it <container_id> /bin/bash

# Example: Access the container with ID 8a18a7ee0838

docker exec -it 8a18a7ee0838 /bin/bash

View Images

radxa@device$
docker images

The terminal will output information similar to the following:

REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 24.04 9d45648b4030 11 days ago 101MB
hello-world latest f1f77a0f96b7 4 months ago 5.2kB

View Containers

radxa@device$
docker ps -a

The terminal will output information similar to the following. You can determine whether a container is running based on the status field:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8a18a7ee0838 ubuntu:24.04 "/bin/bash" 2 minutes ago Up About a minute frosty_beaver
d1799e93de85 hello-world "/hello" 2 minutes ago Exited (0) 2 minutes ago epic_gagarin

Save a Container

If you have made changes to a running container, you can use the docker commit command to save the container as an image for future use.

radxa@device$
docker commit <container_id> <new_image_name>

# Example: Save the container with ID 8a18a7ee0838 as the ubuntu_24_v1 image

docker commit 8a18a7ee0838 ubuntu_24_v1

After successfully saving, the terminal will output information similar to the following:

sha256:be234207cfb6841bbef6bb4639ac2cc035a4bbebdcf5e74a08a8db327a57d569

Stop a Container

If you are inside a running container, type exit to stop the container.

If you are not inside the container, use the docker stop command to stop it.

radxa@device$
docker stop <container_id>

# Example: Stop the container with ID 8a18a7ee0838

docker stop 8a18a7ee0838

After successfully stopping the container, the terminal will output information similar to the following:

8a18a7ee0838

Clean Up Containers

This command only cleans up stopped containers and does not affect running containers.

radxa@device$
docker container prune

The terminal will output information similar to the following. You need to type y to confirm:

WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:yun3
cbb96ce305f30647e03012f979ca604ec31b93f4b1cead64b48d2db85d139171

Total reclaimed space: 5B

Delete an Image

Use the docker rmi command to delete an image.

radxa@device$
docker rmi <image_name>

# Example: Delete the ubuntu:24.04 image

docker rmi ubuntu:24.04

After successfully deleting the image, the terminal will output information similar to the following:

Untagged: ubuntu:24.04
Untagged: ubuntu@sha256:b59d21599a2b151e23eea5f6602f4af4d7d31c4e236d22bf0b62b86d2e386b8f
Deleted: sha256:9d45648b40307b523984e200d90f737b39a705c335fbf484113d4ad0660d97a6
Deleted: sha256:c2f2f00da4ebbfa69fd966cc712f4d400283f6ade9fcd8ebb4801dfae55f86f1