Skip to content

Instantly share code, notes, and snippets.

@albankora
Last active January 4, 2019 20:19
Show Gist options
  • Save albankora/179a28b3aaa3e5f1639e58e7faf3d057 to your computer and use it in GitHub Desktop.
Save albankora/179a28b3aaa3e5f1639e58e7faf3d057 to your computer and use it in GitHub Desktop.

Docker Containers

# run a docker container
$ docker run {image tag} 
# run an docker container on interactive mode 
$ docker run -it {image tag} bash
# run a docker container and remove it when it exits
$ docker run --rm {image tag} 
# check for running containers
$ docker ps
# check for running containers and non running containers
$ docker ps -a
# start a stoped container 
$ docker start {container ID || container name}
# start a stoped container in interactive mode
$ docker start -i {container ID || container name}
# stop a container 
$ docker stop {container ID || container name}
# stop all containers
$ docker stop $(docker ps -aq)
# inspect a docker container
$ docker inspect {container ID || container name}
# remove a container
$ docker rm {container ID || container name}
# remove all containers
$ docker rm $(docker ps -aq)
# check changes done inside docker container
$ docker diff {container ID || container name}

Docker Images

# list all local images
$ docker images
# commit changes done on a docker container to create a new image
$ docker commit -a "Alban Kora" -m "Commit message" {container ID || container name} {commit tag}
# Tag to create a repository with the full registry location.
# The location becomes a permanent part of the repository name.
$ docker tag {image id} {local registry}:{image_tag}
# pull an docker image from the registry
$ docker pull {repository_name:image_tag}
# push a new image to a registry
$ docker push {repository_name:image_tag}
# remove an image
$ docker rmi {image ID || image_name:image_tag}
# remove all images
$ docker rmi $(docker images -q)
# show changes history made on an image
$ docker history {image ID || image_name:image_tag}

Docker Networks

# list all networks 
$ docker network ls
# create a new network 
$ docker network create --driver={driver} {name}
# inspect a network
$ docker network inspect {network name}
# remove a docker volume
$ docker network rm {network_name}
# remove all volumes
$ docker network rm $(docker network ls -q)

Docker Volumes

# list all availiable volumes
$ docker volume ls
# create a local volume and give it a name
$ docker volume create --driver=local --name={name}
# inspect a volume 
$ docker volume inspect {volume_name}
# remove a docker volume
$ docker volume rm {volume_name}
# remove all volumes
$ docker volume rm $(docker volume ls -q)

Docker compose

# list all container from the curent docker-compose
$ docker-compose ps
# see the docker compose config file
$ docker-compose config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment