Docker is a container engine. This means it manages LXC-based containments, lightweight virtual machines. Containments can be an excellent way to isolate applications from the rest of the running system as well as deliver them with their own custom libraries, configuration files, and environments.
Install a specific version of Docker CE:VERSION='some.version.code' bash $(curl -fsSL get.docker.com)
Retrieve general information:docker info
List images:docker images
Remove image:docker rmi [name]
Create a Data Container:docker volume create --name [name]
Export a container's filesystem:docker export -o filesystem-name.tar [name]
Note: this will NOT export the contents of mounted Volumes.
List running containers:docker ps
List all containers:docker ps -a
Run a container:docker run [name]
Run a container as a daemon:docker run -d [name]
Run a container as a daemon with EXPOSEd ports randomly mapped:docker run -d -P [name]
Run a container as a daemon with EXPOSEd ports mapped explicitly:docker run -d -p [source port]:[container port] [name]
Run a container with interactive terminal:docker run -it [name]
Run a container with interactive terminal and running a shell:docker run -it [name] /bin/bash
Run a container with environment variables:docker run -e SOMEVAR1="SOMEVALUE1" -e SOMEVAR2="SOMEVALUE2" [name]
Run a container and override its entrypoint:docker run -it --entrypoint /bin/ash [name]
Save a container's image for all tags:docker save -o backup-name.tar [name]
Save a container's image for the latest tag:docker save -o backup-name.tar [name]:latest
Stop a container:docker kill [name]
Remove a container:docker rm [name]
Show ports used by a container:docker port [name]
Attach Shell to Running Container
After running a container, identify the container ID and use with docker exec.
docker psdocker exec -it [container id] /bin/sh
Run an nginx server detached and accessible by port 80.
docker run -d -p 80:80 --name webserver nginx
Run a Raspberry Pi-focused Redis server with incoming port 6379 mapped to container port 6379 as a daemon with a name, "redis."
docker run -d -p 6379:6379 --name redis frozenfoxx/rpi-redis
Updating an image is relatively straightforward and can allow you to make custom modifications from a default image.
docker pull [user]/[image]docker run -it [user]/[image] /bin/bash[modify]exitdocker ps -a[take note of Container ID for image recently modified]docker commit -m '[commit message]' -a '[author]' [Container ID] [youruser]/[image name]:[version tag]
Build, Tag, and Push
Building your own Docker image requires a Dockerfile. Create one and edit it to suit.
touch Dockerfile && vim Dockerfile
After completing the initial Dockerfile is completed if it references any other files to be copied into the image place them in the current directory.
Run the build command and use -t to tag it to a version and repository.