Docker Help
Docker Help
-----------------------------------------------------------------------------------
--------------------------
docker swarm init --advertise-addr < ip >
docker swarm join --token SWMTKN-1-
2mdgzwqhb03ln1bi8g0j2idibhuykhcug8n5auimhoovk7tb1h-78l1dwn6hzrtcstf5jraacicp
172.16.10.112:2377
-----------------------------------------------------------------------------------
------------------------
You can check the version of Docker you have installed with the following command
from a terminal prompt:
docker --version.
sudo systemctl start docker.
sudo systemctl enable docker.
sudo usermod -a -G docker <username>
Command Description
docker attach Attach local standard input, output, and error streams to a
running container
docker build Build an image from a Dockerfile ###
docker builder Manage builds
docker checkpoint Manage checkpoints
docker commit Create a new image from a container’s changes
docker config Manage Docker configs
docker container Manage containers
docker context Manage contexts
docker cp Copy files/folders between a container and the local filesystem
docker create Create a new container
docker diff Inspect changes to files or directories on a container’s
filesystem
docker events Get real time events from the server
docker exec Run a command in a running container ###
docker export Export a container’s filesystem as a tar archive
docker history Show the history of an image
docker image Manage images ###
docker images List images
docker import Import the contents from a tarball to create a filesystem image
docker info Display system-wide information ###
docker inspect Return low-level information on Docker objects ###
docker kill Kill one or more running containers
docker load Load an image from a tar archive or STDIN
docker login Log in to a Docker registry ##docker tag youtube-dl
<username>/<repository> ##docker push <username>/<repository>
docker logout Log out from a Docker registry
docker logs Fetch the logs of a container ###
docker manifest Manage Docker image manifests and manifest lists
docker network Manage networks ###
docker node Manage Swarm nodes ###
docker pause Pause all processes within one or more containers
docker plugin Manage plugins
docker port List port mappings or a specific mapping for the container
docker ps List containers ###
docker pull Pull an image or a repository from a registry ###
docker push Push an image or a repository to a registry ###
docker rename Rename a container
docker restart Restart one or more containers ###
docker rm Remove one or more containers ###
docker rmi Remove one or more images ###
docker run Run a command in a new container ###
docker save Save one or more images to a tar archive (streamed to STDOUT by
default)
docker search Search the Docker Hub for images ###
docker secret Manage Docker secrets
docker service Manage services ###
docker stack Manage Docker stacks # ejemplo: docker stack deploy up -c
docker-compose.yml
docker start Start one or more stopped containers ###
docker stats Display a live stream of container(s) resource usage statistics
###
docker stop Stop one or more running containers ###
docker swarm Manage Swarm
docker system Manage Docker
docker tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE ###
docker top Display the running processes of a container ###
docker trust Manage trust on Docker images
docker unpause Unpause all processes within one or more containers
docker update Update configuration of one or more containers
docker version Show the Docker version information ###
docker volume Manage volumes
docker wait Block until one or more containers stop, then print their exit
codes
-----------------------------------------------------------------------------------
--------------------------
docker-compose
Building
web:
# build from Dockerfile
build: .
# build from custom Dockerfile
build:
context: ./dir
dockerfile: Dockerfile.dev
Ports
ports:
- "3000"
- "8000:80" # guest:host
# expose ports to linked services (not to host)
expose: ["3000"]
Commands
# command to execute
command: bundle exec thin -p 3000
command: [bundle, exec, thin, -p, 3000]
Environment variables
# environment vars
environment:
RACK_ENV: development
environment:
- RACK_ENV=development
# environment vars from file
env_file: .env
env_file: [.env, .development.env]
Dependencies
# makes the `db` service available as the hostname `database`
# (implies depends_on)
links:
- db:database
- redis
# make sure `db` is alive before starting
depends_on:
- db
Other options
volumes:
- /var/lib/mysql
- ./_data:/var/lib/mysql
Advanced features
Labels
services:
web:
labels:
com.example.description: "Accounting web app"
DNS servers
services:
web:
dns: 8.8.8.8
dns:
- 8.8.8.8
- 8.8.4.4
Devices
services:
web:
devices:
- "/dev/ttyUSB0:/dev/ttyUSB0"
External links
services:
web:
external_links:
- redis_1
- project_db_1:mysql
Hosts
services:
web:
extra_hosts:
- "somehost:192.168.1.100"
Network
-----------------------------------------------------------------------------------
---------------------
-----------------------------------------------------------------------------------
---------------------
Docker run
run [options] [-v VOLUME...] [-p PORT...] [-e KEY=VAL...] [-l KEY=VALUE...]
SERVICE [COMMAND] [ARGS...]
Options:
-d, --detach Detached mode: Run container in the background, print
new container name.
--name NAME Assign a name to the container
--entrypoint CMD Override the entrypoint of the image.
-e KEY=VAL Set an environment variable (can be used multiple times)
-l, --label KEY=VAL Add or override a label (can be used multiple times)
-u, --user="" Run as specified username or uid
--no-deps Don't start linked services.
--rm Remove container after run. Ignored in detached mode.
-p, --publish=[] Publish a container's port(s) to the host
--service-ports Run command with the service's ports enabled and mapped
to the host.
--use-aliases Use the service's network aliases in the network(s) the
container connects to.
-v, --volume=[] Bind mount a volume (default [])
-T Disable pseudo-tty allocation. By default `docker-compose
run`
allocates a TTY.
-w, --workdir="" Working directory inside the container
#Runs a one-time command against a service. For example, the following command
starts the web service and runs bash as its command.
#If you start a service configured with links, the run command first checks to see
if the linked service is running and starts the service if it is stopped. Once all
the linked services are running, the run executes the command you passed it. For
example, you could run:
#If you want to remove the container after running while overriding the container’s
restart policy, use the --rm flag:
#Start the container and expose port 8000 to port 8000 on the host.