Linux: Docker cheat sheet
Docker images
list:
docker images
run image:
docker run full/image/name:version
docker commit changes:
docker commit container-id full/image/name:version
removing images (linked containers need removed first)
docker rmi image-id
save container:
docker export container-id > imagename.tar
load an container:
cat imagename.tar | docker import – full/image/name:version
save image:
docker save full/image/name:version > imagename.tar
load an image:
sudo docker load < imagename.tar
━━━━━━━━━━━━━━━━━━
Docker containers
list:
docker ps -a
execute something within a container:
docker exec -it container-id /bin/bash
run detached:
docker run -d
docker run -it imagename /bin/bash (interacively start bash)
stop a container:
docker stop container-id
removing container
docker rm container-id
Detaching from a container and leave it running
Ctrl+p, Ctrl+q will now turn interactive mode into daemon mode.
Attach to a container
docker attach container-id
Connect inside a container
docker exec -it container-id /bin/bash
Automatically remove a container on exit
docker run –rm -it imagename /bin/bash
━━━━━━━━━━━━━━━━━━
Example Commands Explained
docker run -d -p 5901:5901 -v /etc/machine-id:/etc/machine-id fedora/firefox:version3
docker run -d(detaches the images bringing you back to the host machines command prompt after the container starts) -p(attaches the host ports to the image ports) -v(mounts the local machine ID to the container machine ID) runs a new container off of the image.
docker ps -a
docker ps(list containers and their information including the ID) -a(all)
docker exec -it a42c2a44b79f /bin/bash
docker exec(execute a command in a container) -i(interactive – Keep STDIN open even if not attached) -t(tty – Allocate a pseudo-TTY or a pty) container-id
docker stop a42c2a44b79f
docker stop(Stop the container. The container will be forced stoppeed within 10 seconds unless a delay is specified) container-id
docker rm a42c2a44b79f
docker rm(remove a container) container-id