martes, 18 de abril de 2023

Docker Management Command Cheat Sheet

 https://www.linuxteck.com/docker-management-command-cheat-sheet/

CommandDescriptionExample
Container Commands
docker createCreate a new container from an image.docker create ubuntu:latest
docker startStart with one or more stop containers.docker start my-container
docker stopStop running one or more containers.docker stop my-container
docker restartRestart one or more running containers.docker restart my-container
docker pausePause the process inside a running container.docker pause my-container
docker unpauseUnpause the process inside a paused container.docker unpause my-container
docker renameRename the container.docker rename my-container new-container-name
docker rmRemove one or more containers.docker rm my-container
docker psList the running containers on the host.docker ps
docker statsDisplay real-time resource usage statistics for one or more containers.docker stats my-container
docker topDisplay the processes running inside a container.docker top my-container
docker logsDisplay the logs generated by the container.docker logs my-container
Image Commands
docker pullThis command is used to pull an image from a Docker registry.docker pull ubuntu:latest
docker buildThis command is used to build a new Docker image from a Dockerfile.docker build -t my-image.
docker pushThis command is used to push a Docker image to a Docker registry.docker push my-image
docker tagThis command is used to tag a Docker image with a new name or version.docker tag my-image my-image:latest
docker rmiThis command is used to remove one or more Docker images.docker rmi my-image
docker imagesThis command is used to list the Docker images available on the host.docker images
docker historyThis command is used to display the history of a Docker image.docker history my-image
docker saveThis command is used to save a Docker image to a tar archive.docker save my-image -o my-image.tar
docker loadThis command is used to load a Docker image from a tar archive.docker load -i my-image.tar
Network Commands
docker network createCreate a new Docker networkdocker network create my-network
docker network connectConnect a container to a Docker networkdocker network connect my-network my-container
docker network disconnectDisconnect the container from the Docker networkdocker network disconnect my-network my-container
docker network lsList the Docker networks on the hostdocker network ls
docker network inspectDisplay detailed information about the Docker networkdocker network inspect my-network
docker network rmRemove Docker networkdocker network rm my-network
Volume Commands
docker volume createThis command is used to create a new Docker volume.docker volume create my-volume
docker volume lsThis command is used to list the Docker volumes on the host.docker volume ls
docker volume inspectThis command is used to display detailed information about a Docker volume.docker volume inspect my-volume
docker volume rmThis command is used to remove a Docker volume.docker volume rm my-volume
docker run -vThis option is used to create and mount a volume to a container at runtime.docker run -v my-volume:/app/data my-image
docker inspect -f '{{ .Mounts }}'This command is used to display the mount information of a container, including the volume(s) it's using.docker inspect -f '{{ .Mounts }}' my-container
System Commands
docker versionThis command displays the Docker version information that is currently installed on the system.docker version
docker infoThis command displays Docker system-wide information, including the number of running containers, images, and storage driver information.docker info
docker eventsThis command shows the real-time events from the Docker daemon, such as container creation, deletion, or network creation.docker events
docker system dfThis command shows the disk usage of the Docker system, including space used by images, containers, and volumes.docker system df
docker system pruneThis command is used to free up disk space by removing all unused resources, including containers, images, volumes, and networks.docker system prune
docker loginThis command is used to log in to a Docker registry. You need to authenticate it before pushing or pulling images.docker login
docker logoutThis command is used to log out from the Docker registry.docker logout
Docker Compose Commands
docker-compose upCreate and start all containers defined in the Compose file.docker-compose up
docker-compose downStop and remove all containers defined in the Compose file.docker-compose down
docker-compose buildBuild or rebuild the services defined in the Compose file.docker-compose build
docker-compose startStart all containers defined in the Compose file.docker-compose start
docker-compose stopStop all containers defined in the Compose file.docker-compose stop
docker-compose logsDisplays the logs of all containers defined in the Compose file.docker-compose logs
Docker Swarm Commands
docker swarm initInitialize a new Docker Swarm cluster on the current Docker host.docker swarm init --advertise-addr <manager-node-ip-address>
docker swarm joinJoin a Docker Swarm cluster as a worker node or manager node.docker swarm join --token <join-token> <manager-node-ip-address>:<port>
docker swarm leaveLeave the Docker Swarm cluster by stopping and removing the node from the cluster.docker swarm leave --force
docker stack deployDeploy the Docker stack to the Docker Swarm cluster.docker stack deploy --compose-file <docker-compose-file> <stack-name>
docker service rmRemove the service from the Docker Swarm cluster.docker service rm <service-name>
docker service createCreates a new service in the Docker Swarm cluster.docker service create --name <service-name> --replicas <number-of-replicas> <image-name>
docker service lsList all services in the Docker Swarm cluster.docker service ls
Registry Commands
docker loginLog in to the Docker registry server.docker login myregistry.com
docker logoutLog out from the Docker registry server.docker logout myregistry.com
docker searchSearches for an image on Docker Hub or other registries.docker search nginx
docker pullPull an image from the registry to your local machine.docker pull nginx
docker pushPush an image from your local machine to register.docker push myregistry.com/myimage:tag
docker tagTags an image with a new name and/or tag.docker tag myimage myregistry.com/myimage:tag
Debugging Commands
docker psThis command lists all the running containers with their details such as container ID, image used, command, status, etc.docker ps
docker logsThis command shows the logs of a container.docker logs container_name
docker execThis command is used to execute a command inside a running container.docker exec container_name ls -l /
docker inspectThis command is used to get detailed information about a container or an image.docker inspect container_name
docker portThis command is used to list the port mappings of a container.docker port container_name
docker topThis command is used to see the processes running inside a container.docker top container_name
Dockerfile Commands
FROMset the base image to build the Dockerfile.FROM ubuntu:latest
RUNrun the command during the image building process.RUN apt-get update && apt-get install -y curl
COPYcopy files and directories from the host into the Docker image.COPY app /app
CMDspecifies the default command to run the container starts.CMD ["node", "app.js"]
WORKDIRset the working directory for any RUN, CMD, ENTRYPOINT, COPY, or ADD commands that follow it.WORKDIR /app
ENVsets of environmental variables that can be used during the image building process or when the container is running.ENV NODE_ENV production
EXPOSEdocument the ports that the container listens to at runtime.EXPOSE 8080
VOLUMEcreate a mount point for the volume in the container.VOLUME /data
USERset the user or UID to where the container should run as.USER node
Multi-Stage Build Commands
FROMSpecify the base image to start the build process.FROM alpine:latest
WORKDIRSet a working directory for any RUN, CMD, ENTRYPOINT, COPY, and ADD commands that follow it.WORKDIR /app
COPYCopying files or directories from the build context into the container.  Suitable for multiple uses.COPY app.py /app/
RUNExecutes a command inside the container during build time.RUN pip install -r requirements.txt
ARGDeclares a variable that can be passed on to the Docker build command using --build-arg.ARG version
CMD or ENTRYPOINTDuring container startup, both are Dockerfile instructions that specify what command to run.["python", "app.py"]
ENVSets environment variables for the container.ENV FLASK_APP=app.py
LABELLabel describes an image or container as a key-value pair.LABEL <'key'>=<'value'>
Health Check Commands
HEALTHCHECKUsing this command, you can check the health of a container.HEALTHCHECK --interval=5m --timeout=3s CMD curl -f http://localhost/ || exit 1
docker inspect --format='{{json .State.Health}}' <container>Using this command, you can inspect a container's health status and get detailed information about its current state.docker inspect --format='{{json .State.Health}}' my-container
docker container ls --filter health=unhealthyThis command is used to list all containers that have a failed health check.docker container ls --filter health=unhealthy
Config Commands
docker config createCreates a new config with the specified name and content.docker config create myconfig myconfig.txt
docker config inspectDisplays detailed information about the config.docker config inspect myconfig
docker config lsList all configs.docker config ls
docker config rmRemove one or more configs.docker config rm myconfig
docker config updateUpdates the config with new content.docker config update myconfig myconfig-updated.txt
docker service createCreate a new service with one or more configs.docker service create --name myservice --config source=myconfig,target=/app/config.txt myimage
docker service updateUpdate a service with one or more configs.docker service update --config-rm myoldconfig --config-add mynewconfig myservice
Buildx Commands
docker buildx lsList all the available builders.docker buildx ls
docker buildx createCreates a new builder instance.docker buildx create --name mybuilder
docker buildx useSets the current builder context.docker buildx use mybuilder
docker buildx inspectDisplays detailed information about the current builder instance.docker buildx inspect --bootstrap
docker buildx buildBuilds an image using the current builder context.docker buildx build --platform linux/amd64,linux/arm64 -t myimage:latest

No hay comentarios:

Publicar un comentario