0% found this document useful (0 votes)
22 views

Docker Help

Uploaded by

Thomas Bell
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Docker Help

Uploaded by

Thomas Bell
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

olFix :GPG error: https://download.docker.

com/linux/ubuntu focal InRelease: The


following signatures couldn't be verified because the public key is not available:
NO_PUBKEY 7EA0A9C3F273FCD8
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o
/usr/share/keyrings/docker-archive-keyring.gpg

-----------------------------------------------------------------------------------
--------------------------
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 system prune # limpia imagenes,contenedores, redes y volumenes que no estan


asociados a un contenedor.
docker system prune -a # limpia contenedores parados y imagenes sin uso.
docker images -a # lista cada imagen incluyendo capas intermedias ###
docker rmi Image Image # borra imagenes ###
docker images -f dangling=true # localiza imagenes sin usos o sin etiquetas.por lo
tanto al crear imagenes se recomienta taggearlas para que no aparezca como en
desuso.
docker images -a | grep " pattern " # localiza imagenes que cumplan con un patron
docker ps -a # lista todos los contenedores.###
docker rm ID_or_Name ID_or_Name #borra contenedores .deben estar detenidos###
docker run --rm image_name # corre un contenedor y lo borra.###
docker ps -a -f status=exited # lista contenedores filtrados por estados: created
restarting running paused exited.###
docker ps -a -f status=exited -f status=created #filtra por 2 estados.
docker rm $(docker ps -a -f status=exited -f status=created -q) # elimina
contenedores filtrados por estados.
docker volume ls # lista volumenes ###
docker volume rm volume_name volume_name # borra volumenes. ###
docker rm -v container_name #borra contenedor y su volumen ###
docker commit #útil para confirmar los cambios o la configuración del archivo de un
contenedor en una nueva imagen
docker save # salva una o mas imagenes a un archivo tar ejemplo:(comprimido tar
gz )docker save myimage:latest | gzip > myimage_latest.tar.gz ###
docker load # importa una imagen de un archivo tar o STDIN ejemplo: docker load <
busybox.tar.gz ###

-----------------------------------------------------------------------------------
--------------------------
docker-compose

docker-compose --version. # version de docker

docker-compose up -d #crea contrenedores basados en el fichero docker-


compose.yaml en modo desatachdo.
docker-compose down # elimina contenedores y redes pero mantiene las bases de
datos.
docker-compose down --volumes # elimina contenedores y redes asi como tambien las
bases de datos.

docker-compose start # Starts existing containers for a service.


docker-compose stop# Stops running containers without removing them.
docker-compose pause # Pauses running containers of a service.
docker-compose unpause # Unpauses paused containers of a service.
docker-compose ps # Lists containers.
docker-compose up # Builds, (re)creates, starts, and attaches to containers for a
service.
docker-compose down # Stops containers and removes containers, networks, volumes,
and images created by up.

##Config file reference

Building
web:
# build from Dockerfile
build: .
# build from custom Dockerfile
build:
context: ./dir
dockerfile: Dockerfile.dev

# build from image


image: ubuntu
image: ubuntu:14.04
image: tutum/influxdb
image: example-registry:4000/postgresql
image: a4bc65fd

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]

# override the entrypoint


entrypoint: /app/start.sh
entrypoint: [php, -d, vendor/bin/phpunit]

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

# make this service extend another


extends:
file: common.yml # optional
service: webapp

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

# creates a custom network called `frontend`


networks:
frontend:
External network

# join a preexisting network


networks:
default:
external:
name: frontend

-----------------------------------------------------------------------------------
---------------------

-----------------------------------------------------------------------------------
---------------------
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.

docker-compose run web bash

#Alternatively, manual port mapping can be specified with the --publish or -p


options, just as when using docker run:

docker-compose run --publish 8080:80 -p 2022:22 -p 127.0.0.1:2021:21 web python


manage.py shell

#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:

docker-compose run db psql -h db -U docker

#If you want to remove the container after running while overriding the container’s
restart policy, use the --rm flag:

docker-compose run --rm web python manage.py db upgrade

#Start the container and expose port 8000 to port 8000 on the host.

docker run --publish 8000:8000 node-docker

docker push ernoserna/devops:tagname

You might also like