Skip to content

Instantly share code, notes, and snippets.

@jrichardsz
Last active September 23, 2022 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrichardsz/478f410ee3bf17e1abd3c65bc712279c to your computer and use it in GitHub Desktop.
Save jrichardsz/478f410ee3bf17e1abd3c65bc712279c to your computer and use it in GitHub Desktop.
docker snippets, dockerminimal, dockerstarter, dockersandbox, dockersnippet, zombi, inmortal
create a new centos-7
docker run -it centos:centos7
install docker inside it with official steps
https://docs.docker.com/engine/install/centos/#install-using-the-repository
sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io

format images

https://docs.docker.com/engine/reference/commandline/images/#format-the-output https://docs.docker.com/engine/reference/commandline/images/

docker image list --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}" docker image list --format "table {{.Repository}}\t{{.ID}}\t{{.CreatedAt}}" docker image list --format "table {{.ID}}\t{{.CreatedAt}}"

Format the output

The formatting option (--format) will pretty print container output using a Go template.

Valid placeholders for the Go template are listed below: Placeholder Description .ID Image ID .Repository Image repository .Tag Image tag .Digest Image digest .CreatedSince Elapsed time since the image was created .CreatedAt Time when the image was created .Size Image disk size

clear unused

docker rmi $(docker images -f "dangling=true" -q)

RUN echo 'while true; do echo "$(date)" && sleep 2; done' > /bootstrap.sh
RUN chmod +x /bootstrap.sh
CMD /bootstrap.sh
docker run -it ubuntu
docker run --name ubuntu -it ubuntu
docker run --name python -it python:2
# build
docker build --rm -t ubuntu_nodejs:10 .
docker build --no-cache --rm -t ubuntu_nodejs:10 .
# run with path
docker run -d --name ruby -v /foo/bar:/opt/app -it ubuntu
# workaround in order to keep a live docker container
while true
do
sleep 300
## docker show real build log
export BUILDKIT_PROGRESS=plain
docker build --progress=plain -t docs .
services:
build:
progress: plain
done
python:2
## remove all except: acme and foo containers
docker rm $(docker ps -a | grep -v -E "acme|foo" | cut -d ' ' -f1)
### nodejs
docker run -it --name node10 ubuntu
## docker ps filter
docker ps -a --format="table {{.Names}}\t{{.Image}}\t{{.Status}}"
FROM ubuntu
# Create directory
RUN mkdir /testdir
RUN echo "Hello world">> /testdir/hello2.txt
CMD /bin/bash
docker run --name ubuntu -it ubuntu
apt update
apt-get install git
https://hub.docker.com/r/crccheck/hello-world
docker run -d --rm --name web-test -p 80:8000 crccheck/hello-world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment