Skip to content

Instantly share code, notes, and snippets.

@brihter
Last active May 8, 2024 18:20
Show Gist options
  • Save brihter/903103260e69f2efe3150d2b136fc4f1 to your computer and use it in GitHub Desktop.
Save brihter/903103260e69f2efe3150d2b136fc4f1 to your computer and use it in GitHub Desktop.
docker cheatsheet
# get image
docker pull neo4j
# list
docker ps # show running containers
docker ps -a # + show all
# new
docker run neo4j # create a new container
docker run --name neo4j-local neo4j # + add a name
docker run --name neo4j-local --publish=7474:7474 --publish=7687:7687 neo4j # + port forwarding
docker run --name neo4j-local --publish=7474:7474 --publish=7687:7687 -d=true neo4j # + run in detached mode
# start, stop, restart, kill, rm
docker {operation} b5de13cd1fd6 # operation by id
docker {operation} neo4j-local # operation by name
docker start neo4j-local
docker stop neo4j-local
docker kill neo4j-local
docker rm neo4j-local
# files
docker cp data/ neo4j-local:/tmp/kfc-data/ # copy local folder to container
docker cp 02314e287040:/data.json data.json # copy container to local
docker exec neo4j-local rm -rf /tmp/kfc-data/ # remove container folder
# shell
docker exec -it neo4j-local /bin/bash # connect to container
docker run -i -t amazonlinux:2018.03 /bin/bash
# image management
docker images ## list all images
docker rmi $(docker images -q) ## remove all images
docker save --output img-latest.tar img:latest
docker load --input img-latest.tar
# container management
docker rm $(docker ps --filter status=exited -q) ## remove all stopped containers
# logs
sudo du -ch $(docker inspect --format='{{.LogPath}}' $(docker ps -qa)) | tail -n1 # logs size
sudo echo "" > $(docker inspect --format='{{.LogPath}}' <container_name_or_id>) # clear logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment