Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Terms
- Image: Operating system image, stored in a repo. Single file. A template for an image
- Dockerfile: Definition of an image (source code of an image)
- Container: Instance of an image
- Registry: A repository to push and pull containers (like git)
- Microservices: Single process per container
- Fat containers: Similar to a virtual machine
- // Notes
- - Digitalocean guides are a great resource!
- - By default, only root can use docker (attach to the docker daemon)
- - If you want non-priv users to use docker, do that through sudo
- OR
- - create a docker group and add them to it
- - By default, Docker containers do persist data when stopped, then started/exec'd later
- - By default, Docker containers do NOT persist data across "runs" (new containers from image)
- - Use docker data volumes to persist changes
- - See "data volume" containers and "--volumes-from" option when starting a container
- - You can also share data between the host and container
- - See docker run "-v" option
- - Docker generates random container names for you if you don't specify a name
- // Determine how much space docker is using
- docker system df
- // Clean up unused base images and shit taking up disk space, especially in /var/lib/docker/overlay2/
- docker system prune -a
- // Remove all build cache
- docker buildx prune --all
- docker builder prune --all
- // Installing LATEST version of docker on CentOS 7 (not version that comes with CentOS)
- https://github.com/NaturalHistoryMuseum/scratchpads2/wiki/Install-Docker-and-Docker-Compose-(Centos-7)
- // Installing LATEST docker-compose
- curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- // Show docker version
- docker version
- // show all info about the docker environment
- docker info
- // Search docker registry for any image with name "centos"
- docker search centos
- // Download latest centos image from the registry
- docker pull docker.io/centos
- // Download specific tagged centos image
- docker pull docker.io/centos:centos7.0.1406
- // Push centos 7.0 image with id cc2cf48cc784 to a remote registry
- docker tag cc2cf48cc784 gitlabserver.nucleussec.com:8443/root/vulndockerimages/centos7.0
- docker push gitlabserver.nucleussec.com:8443/root/vulndockerimages/centos7.0
- // See all images that have been downloaded
- docker images -a
- // Save a docker image to a tarfile
- docker save someimage > someimage.tar
- // show all running containers
- docker ps
- // stop a running container
- docker stop <container id>
- // stop all containers
- docker stop $(docker ps -aq)
- // restart a container
- docker start <container id>
- // commit a copy of the container (presumably with changes from the base image) to a new image
- docker commit -m "<comment>" -a "<author>" <container id> <new image name>
- // remove a stopped docker containers
- docker rm <container id>
- // remove all containers
- docker rm $(docker ps -aq)
- // show all docker containers running or stopped
- docker ps -a
- // show running processes in a container
- docker top <container id>
- // look at all info on a container
- docker inspect <container id>
- // Downloads/pulls latest centos (centos:latest) image from docker.io and runs cat command
- docker run -it centos cat /etc/redhat-release
- // Same thing but automatically clean up the container and remove the file system when the container exits
- docker run --rm -it centos cat /etc/redhat-release
- // spin up a new container named "mycontainer" from a docker image and get shell inside
- docker run -it --name="mycontainer" <image name> /bin/bash
- // mount a host volume/dir
- -v
- // after container runs the command, stop, then delete itself
- --rm
- // Get a shell in a running container
- docker exec -it <container name> /bin/bash
- // Edit a file in a container that doesn't have an editor
- docker cp <container>:/path/to/file.ext .
- // copies it to your local machine (to your current directory).
- // Then edit the file locally using your favorite editor, and then:
- docker cp file.ext <container>:/path/to/file.ext
- // to replace the old file.
- #### Docker Compose ####
- # docker-compose up // in same directory as docker-compose.yml
- # docker-compose up -d // start containers in background (instead of dying when terminal dies)
- # docker-compose stop // in same directory as docker-compose.yml
- # docker-compose ps // show running containers
- # docker-compose rm // start from scratch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement