docker
docker is the base command for the Docker CLI.[1]
Documentation
Syntax
docker [GLOBAL-PARAMETER ...] SUBCOMMAND [PARAMETER ...]
Subcommands & Parameters
- exec
- Run a command in a running container.
- images
- List images.
- -f KEY=VALUE, --filter KEY=VALUE
- Filter output based on conditions provided.
- -q, --quiet
- Only show numeric IDs
- logs
- Fetch the logs of a container.
- -f, --follow
- Follow log output.
- network create
- Create a network.
- -d bridge|overlay, --driver bridge|overlay
- Driver to manage the Network
- ps
- List containers.
- -a, --all
- Show all containers (default shows just running).
- -f KEY=VALUE, --filter KEY=VALUE
- Filter output based on conditions provided.
- -l, --latest
- Show the latest created container (includes all states).
- pull
- Pull an image or a repository from a registry.
- restart
- Restart one or more containers.
- rm
- Remove one or more containers.
- -f, --force
- Force the removal of a running container (uses SIGKILL).
- -v, --volumes
- Remove the volumes associated with the container.
- rmi
- Remove one or more images.
- -f, --force
- Force removal of the image.
- run
- Run a command in a new container.
- -d, --detach
- Run container in background and print container ID.
- -e VAR[=VALUE], --env VAR[=VALUE]
- Set environment variables.
- --env-file FILE
- Read in a file of environment variables.
- --name NAME
- Assign a name to the container.
- --net NAME, --network NAME
- Connect a container to a network.
- -p HOST_PORT:CONTAINER_PORT,
--publish HOST_PORT:CONTAINER_PORT - Publish a container’s port(s) to the host.
- -v [HOST_PATH:]CONTAINER_PATH,
--volume [HOST_PATH:]CONTAINER_PATH - Bind mount a volume.
- start
- Start one or more stopped containers.
- stop
- Stop one or more running containers.
Examples
name='mariadb_1'
net='db-net'
storage='/var/lib/docker/volumes'
etc='etc/mysql/conf.d/atlassian.cnf'
var='var/lib/mysql'
docker network create --driver 'bridge' "${net}"
cat >"${HOME}/conf/${name}.env"
MYSQL_ROOT_PASSWORD=**********
for dir in "${storage}/${name}/_data/${etc%/*}" \
"${storage}/${name}/_data/${var}"
do
[[ ! -d "${dir}" ]] && mkdir -p "${dir}"
done
cat >"${storage}/${name}/_data/${etc}"
[mysqld]
innodb_log_file_size = 256M
max_allowed_packet = 64M
transaction-isolation = READ-COMMITTED
docker run \
--detach \
--env-file "${HOME}/conf/${name}.env" \
--name "${name}" \
--network "${net}" \
--volume "${storage}/${name}/_data/${etc}:/${etc}" \
--volume "${storage}/${name}/_data/${var}:/${var}" \
'mariadb:latest'
rm "${HOME}/conf/${name}.env"
- Delete all untagged images
docker rmi $(docker images --filter 'dangling=true' --quiet)