Skip to content

Instantly share code, notes, and snippets.

@neklaf
Last active May 3, 2020 09:11
Show Gist options
  • Save neklaf/f9fcf634d19110c01a69ce1797c0a64c to your computer and use it in GitHub Desktop.
Save neklaf/f9fcf634d19110c01a69ce1797c0a64c to your computer and use it in GitHub Desktop.
Some useful docker commands

Allow non-priviledged user run docker commands

# usermod -aG docker ${USER}

Stop and remove all docker containers

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rm $(docker ps -a -q -f status=exited)

Cleaning docker images

docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

Review or check some docker container configuration

docker ps --quiet | xargs docker inspect --format '{{ .Id }}: Ports={{ .NetworkSettings.Ports }}'
docker ps --quiet --all | xargs docker inspect --format '{{ .Id }}: Propagation={{range $mnt := .Mounts}} {{json $mnt.Propagation}} {{end}}'
docker ps --quiet --all | xargs docker inspect --format '{{ .Id }}: SecurityOpt={{.HostConfig.SecurityOpt }}'

Run some containers

docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.6.1
docker run --volume=/hostPath:/containerPath:shared <image> <command>
docker run <run-options> --security-opt=no-new-privileges <image> <cmd>
docker run --device /dev/kvm:/dev/kvm -v $PWD/backing:/backing -p 2222:2222 -p 5900:5900 -p 5800:5800 cleafy/sxkdvm
docker run -d -m 1g -p 10000-10035:10000-10035 --shm-size 1g --name agraph franzinc/agraph:v6.2.2

Run GUI apps on macOS

socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
docker run --rm -e DISPLAY=docker.host.internal:0 -e LD_LIBRARY_PATH=/usr/lib kartoza/qgis-desktop qgis

Building an docker container

docker build -t <image>:<tag> .

Modifying docker images

docker commit -m "What you did to the image" -a "Author Name" container_id repository/new_image_name
docker commit -m "added foo.js" -a "dude" d42d0bbfbd35 sammy/ubuntu-nodejs

Extracting files from a docker image

docker run --rm --entrypoint cat sammy/ubuntu-nodejs /path/to/file > path/to/destination

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment