docker - commands
sudo docker kill $(docker ps -q)
sudo docker rm $(docker ps -a -q)
sudo service docker restart # If this does not work
# enter
docker exec -it my_container bash
#--------------images---------------------
# all active images
docker images
# content-addressable identifier called a digest
docker images --digests | head
# get single image
docker images wordpress
# all images
docker images -a
#return only ID
docker images -q
# find image
docker images --no-trunc|grep memcached
# check image exist
IMAGE=$(docker images | grep "user/repo" | awk '{print $3}')
if [[ -z $IMAGE ]]; then
dokku_log_fail "user/repo image not found... Did you run 'dokku plugin:install'?"
fi
# -------------------------information--------------------------
docker inspect some-mysql
docker inspect some-mysql | grep IPAddress
docker inspect -f '{{.Id}}' SHORT_CONTAINER_ID-or-CONTAINER_NAME
#find ip address
docker inspect --format {{.NetworkSettings.IPAddress}} stupefied_turing
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ID
# get entrypoint script in image
docker inspect --format '{{range .Config.Entrypoint}}{{.}} {{end}}' "$IMAGE"
# get CMD in docker image
docker inspect --format '{{range .Config.Cmd}}{{.}} {{end}}' "$IMAGE"
# list of files that have changed in the running container.
docker diff some-wordpress
# get running processes inside a given container
docker top $ID
## find out which public port in context is bound to the private port 80 in container.
# find out which public port is bound to the private port 80
docker port some-wordpress 80
docker port 7371 80 #or specific container id
docker port 7371 #or get all forward
$ docker port $ID 6379/tcp
0.0.0.0:32768
### status
# lists the running containers.
docker ps
# lists all the containers, both running and exited
docker ps -a
# gets the IDs of all stopped containers
docker ps -aq -f status=exited
# get id from name
ID=$(docker ps -f status=running | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true
# get docker container name by PID
docker ps -q | xargs docker inspect --format '{{.State.Pid}}, {{.ID}}' | grep "^${PID},"
# get container name by id
local c_name=$(docker inspect -f '{{.Name}}' $(cat $DOKKU_CONTAINER_ID_FILE) | cut -f2 -d"/")
# ----------------------log
docker logs 9ad7
#_------------------------SSH---------------------------
docker run -i -t debian /bin/bash # during run container
docker exec -it some-wordpress bash
#---------------------run/start/stop container---------------------------
# start a container
docker run --name some-wordpress --link some-mysql:mysql -d wordpress
# launching a container, give it a new hostname
docker run -h CONTAINER -i -t debian /bin/bash
# download image from reposi & run container
docker pull redis
docker run --name myredis -d redis
# Locally Accessible container
docker run -p 127.0.0.1::80 tutum/wordpress
# stop
docker stop some-mysql
# start or active
docker start some-mysql
docker start some-wordpress
docker start -a <containerID>
# pause, Suspends all processes inside the given container
docker pause <container>
# Restarts a container previously paused
docker unpause <name|ID>
# stop & start
docker restart <name|ID>
docker restart `cat /home/dokku/myapp/CONTAINER`
# Sends a signal to the main process (PID 1) in a container, by default send SIGKILL
docker kill -s SIGTRAP $ID
#--------------------remove------------------------
# remove container
docker rm <name|ID>
# clean all your stopped containers
docker rm -v $(docker ps -aq -f status=exited)
# delete all dead containers
docker rm $(docker ps -a -f "status=dead" -q)
# remove all leftover containers
docker rm $(docker ps -aq)
## remove images:
docker rmi image-ID/repository
# remove all dangling images:
docker rmi $(docker images -q -f dangling=true)
# Remove all untagged images
docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
#------------------------copy file----------------------------
# copy files from local to inside container
docker cp some-nginx:/etc/nginx/nginx.conf /some/nginx.conf
# other solution
sudo cp path-file-host /var/lib/docker/aufs/mnt/FULL_CONTAINER_ID/PATH-NEW-FILE
# solution 2
cd /tmp/somefiles
tar -cv * | docker exec -i elated_hodgkin tar x -C /var/www