Skip to content

Instantly share code, notes, and snippets.

@splincode
Last active October 6, 2021 15:05
Show Gist options
  • Save splincode/d61deb5719096468cb2ee3f794bd2ac4 to your computer and use it in GitHub Desktop.
Save splincode/d61deb5719096468cb2ee3f794bd2ac4 to your computer and use it in GitHub Desktop.

Container is a replica of container, image is a blueprint

List container activitily

$ docker ps -a

List installed images

$ docker image ls

Example

$ docker run ubuntu
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
f3ef4ff62e0d: Pull complete 
Digest: sha256:a0d9e826ab87bd665cfc640598a871b748b4b70a01a4f3d174d4fb02adad07a9
Status: Downloaded newer image for ubuntu:latest

$ docker image ls
REPOSITORY                                                         TAG          IMAGE ID       CREATED         SIZE
ubuntu                                                             latest       597ce1600cf4   5 days ago      72.8MB

$ docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED          STATUS                      PORTS     NAMES
0a62cb3952b8   ubuntu    "bash"    52 seconds ago   Exited (0) 51 seconds ago             romantic_bell

$ docker run -it -d ubuntu
2362f603c44bff9e0798af92761802ca8cc429f0664ab35b765cb038b682f392

$ docker ps -a     
CONTAINER ID   IMAGE     COMMAND   CREATED         STATUS                     PORTS     NAMES
6565a1ceb30f   ubuntu    "bash"    1 second ago    Exited (0) 1 second ago              beautiful_lamarr
2362f603c44b   ubuntu    "bash"    2 minutes ago   Up 2 minutes                         interesting_wilson
2362f603c44b
$ docker exec -it 2362f603c44b bash 
root@2362f603c44b:/#

Stop and remove all

$ docker stop $(docker ps -a -q)
$ docker rm $(docker ps -a -q)

Commit our changes

$ docker commit 2baefe78caff splincode/ubuntu-modified
sha256:a238bb4a7712bf133f0a6d5e19db8cd746b450a57ac948cd538c6a9d10dd0608

$ docker login
$ docker push

$ docker image ls
REPOSITORY                                                         TAG          IMAGE ID       CREATED         SIZE
splincode/ubuntu-modified                                          latest       a238bb4a7712   6 minutes ago   72.8MB
ubuntu                                                             latest       597ce1600cf4   5 days ago      72.8MB

$ docker rmi splincode/ubuntu-modified

$ docker image ls
REPOSITORY                                                         TAG          IMAGE ID       CREATED         SIZE
ubuntu                                                             latest       597ce1600cf4   5 days ago      72.8MB

Remove all images

$ docker rmi -f $(docker images -a -q)

Tag

$ docker build -t ${IMAGE}:${VERSION} .
$ docker tag ${IMAGE}:${VERSION} ${IMAGE}:latest

https://www.youtube.com/watch?v=3c-iBn73dDE&ab_channel=TechWorldwithNana https://www.youtube.com/watch?v=dU5112nqViY&ab_channel=Refactored

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