Docker
docker ps
docker ps -a
docker images
docker pull ubuntu
docker run ubuntu
docker run -it ubuntu /bin/bash
docker stop <container_id>
docker start <container_id>
docker restart <container_id>
docker rm <container_id>
docker rmi <image_id>
docker exec -it <container_id> /bin/bash
docker logs <container_id>
docker inspect <container_id>
docker build -t myapp .
docker run -d myapp
docker commit <container_id> mynewimage
docker tag myapp:latest myrepo/myapp:1.0
docker push myrepo/myapp:1.0
docker pull myrepo/myapp:1.0
docker network ls
docker network create mynetwork
docker network connect mynetwork <container_id>
docker network disconnect mynetwork <container_id>
docker volume create myvolume
docker volume ls
docker volume rm myvolume
docker cp <container_id>:/path/to/file /local/path
docker cp /local/path <container_id>:/path/to/file
docker stats <container_id>
docker top <container_id>
docker rename <container_id> new_name
docker history <image_id>
docker diff <container_id>
docker pause <container_id>
docker unpause <container_id>
docker system prune -f
docker image prune -f
docker container prune -f
docker events
docker save myimage > myimage.tar
docker load -i myimage.tar
docker login
docker logout
docker system df
docker export <container_id> > mycontainer.tar
docker import mycontainer.tar
docker search ubuntu
docker inspect --format='{{.NetworkSettings.IPAddress}}' <container_id>
docker run -p 8080:80 myapp
-
Start a container with a specific image
docker run ubuntu
-
Run an image in interactive mode with a shell
docker run -it ubuntu /bin/bash
-
Run a container in the background
docker run -d ubuntu
-
Run a container with a custom name
docker run --name mycontainer ubuntu
-
Run a container and automatically remove it when stopped
docker run --rm ubuntu
-
Run a container with a specified command
docker run ubuntu echo "Hello, Docker!"
-
Run a container with an environment variable
docker run -e MY_ENV_VAR=value ubuntu
-
Run a container with multiple environment variables
docker run -e VAR1=value1 -e VAR2=value2 ubuntu
-
Run a container with a custom hostname
docker run --hostname myhostname ubuntu
-
Run a container with limited CPU usage
docker run --cpus="1.5" ubuntu
-
Run a container with limited memory
docker run -m 512m ubuntu
-
Run a container and map a host port to the container
docker run -p 8080:80 nginx
-
Run a container with a custom network
docker run --network mynetwork ubuntu
-
Run a container and link it to another container
docker run --link othercontainer:alias ubuntu
-
Run a container with a specified user
docker run -u 1001 ubuntu
-
Run a container and mount a host directory
docker run -v /host/path:/container/path ubuntu
-
Run a container in privileged mode
docker run --privileged ubuntu
-
Run a container with read-only root filesystem
docker run --read-only ubuntu
-
Run a container with restart policy (always)
docker run --restart always ubuntu
-
Run a container with restart policy (on-failure)
docker run --restart on-failure ubuntu
-
Run a container with log driver set to JSON
docker run --log-driver json-file ubuntu
-
Run a container and specify the PID namespace
docker run --pid=host ubuntu
-
Run a container with custom DNS
docker run --dns 8.8.8.8 ubuntu
-
Run a container with a specific MAC address
docker run --mac-address="02:42:ac:11:65:43" ubuntu
-
Run a container with security options
docker run --security-opt seccomp=unconfined ubuntu
-
Run a container with specific working directory
docker run -w /app ubuntu
-
Run a container with limited I/O bandwidth
docker run --device-write-bps /dev/sda:1mb ubuntu
-
Run a container and expose a specific port
docker run -P -d nginx
-
Run a container and specify a custom entrypoint
docker run --entrypoint /my-script.sh ubuntu
-
Run a container and specify both entrypoint and command
docker run --entrypoint /bin/cat ubuntu /etc/hosts
-
Run a container and join an existing network namespace
docker run --network container:<container_id> ubuntu
-
Run a container in detached mode and log stdout to a file
docker run -d ubuntu > mylog.txt
-
Run a container with a health check
docker run --health-cmd="curl --fail http://localhost || exit 1" ubuntu
-
Run a container in a custom IPC mode
docker run --ipc=host ubuntu
-
Run a container and give it additional capabilities
docker run --cap-add=NET_ADMIN ubuntu
-
Run a container with limited number of open files
docker run --ulimit nofile=1024:1024 ubuntu
-
Run a container with specific stop signal
docker run --stop-signal SIGUSR1 ubuntu
-
Run a container with limited swap memory
docker run -m 512m --memory-swap 1g ubuntu
-
Run a container with a device mounted
docker run --device=/dev/sda:/dev/xvdc ubuntu
-
Run a container in detached mode and attach later
docker run -d --name myapp ubuntu && docker attach myapp
-
Run a container and set its init process
docker run --init ubuntu
-
Run a container with a custom group ID
docker run --group-add 1001 ubuntu
-
Run a container with restricted read and write permissions
docker run -v /host/path:/container/path:ro ubuntu
-
Run a container with CPU shares to prioritize
docker run --cpu-shares 512 ubuntu
-
Run a container with specific hostname and domain name
docker run --hostname myhost --domainname mydomain ubuntu
-
Run a container with a custom label
docker run --label env=dev ubuntu
-
Run a container in interactive mode with automatic reattach
docker run --interactive --tty --detach-keys="ctrl-c" ubuntu
-
Run a container with a custom cgroup parent
docker run --cgroup-parent /docker ubuntu
-
Run a container and use
sysctl
settings
docker run --sysctl net.ipv4.ip_forward=1 ubuntu
-
Run a container and log to specific log driver
docker run --log-driver=fluentd ubuntu
-
List running containers
docker ps
-
List all containers, including stopped ones
docker ps -a
-
Start a stopped container
docker start <container_id>
-
Stop a running container
docker stop <container_id>
-
Restart a container
docker restart <container_id>
-
Remove a stopped container
docker rm <container_id>
-
Force remove a running container
docker rm -f <container_id>
-
Rename a container
docker rename <old_name> <new_name>
-
Inspect a container’s details
docker inspect <container_id>
-
View container logs
docker logs <container_id>
-
Follow live logs of a container
docker logs -f <container_id>
-
View the top processes in a container
docker top <container_id>
-
Run a command in a running container
docker exec -it <container_id> /bin/bash
-
Copy a file from container to host
docker cp <container_id>:/path/in/container /path/on/host
-
Copy a file from host to container
docker cp /path/on/host <container_id>:/path/in/container
-
Pause a container
docker pause <container_id>
-
Unpause a paused container
docker unpause <container_id>
-
List all paused containers
docker ps --filter "status=paused"
-
Get container stats (CPU, memory, etc.)
docker stats <container_id>
-
Change a container’s resource limits
docker update --cpus="1.5" --memory="512m" <container_id>
-
Limit the number of restart attempts
docker update --restart=on-failure:3 <container_id>
-
Attach to a running container
docker attach <container_id>
-
Detach from a container without stopping it
docker attach --detach-keys="ctrl-c" <container_id>
-
Check container health status
docker inspect --format='{{json .State.Health.Status}}' <container_id>
-
List containers by name filter
docker ps -f "name=mycontainer"
-
List containers by status filter
docker ps -f "status=exited"
-
List containers based on label
docker ps --filter "label=env=prod"
-
Get the container’s IP address
docker inspect --format='{{.NetworkSettings.IPAddress}}' <container_id>
-
Change container restart policy to always
docker update --restart=always <container_id>
-
Kill a container (send SIGKILL)
docker kill <container_id>
-
Kill a container with a custom signal
docker kill --signal="SIGUSR1" <container_id>
-
Remove all stopped containers
docker container prune -f
-
Remove containers older than 24 hours
docker container prune --filter "until=24h"
-
List containers sorted by size
docker ps --size --sort=size
-
List containers in JSON format
docker ps -a --format "{{json .}}"
-
List containers showing only IDs
docker ps -q
-
Show the last created container
docker ps -l
-
Show the most recent container logs
docker logs $(docker ps -q -n 1)
-
Limit logs to last 10 lines
docker logs --tail 10 <container_id>
-
Remove all exited containers
docker rm $(docker ps -q -f "status=exited")
-
Restart all containers
docker restart $(docker ps -q)
-
Stop all running containers
docker stop $(docker ps -q)
-
Display containers grouped by image
docker ps --filter ancestor=nginx
-
Show the container’s start time
docker inspect -f '{{.State.StartedAt}}' <container_id>
-
Export a container’s filesystem to a .tar file
docker export <container_id> > container_backup.tar
-
Import a saved container .tar file
docker import container_backup.tar
-
Limit a container’s file descriptors
docker update --ulimit nofile=1024:1024 <container_id>
-
Set the container’s stop timeout
docker update --stop-timeout 30 <container_id>
-
Assign a container to a new network
docker network connect mynetwork <container_id>
-
Disconnect a container from a network
docker network disconnect mynetwork <container_id>